Re: reg expr...

"Torben Ęgidius Mogensen" <>
12 Sep 2002 14:13:20 -0400

          From comp.compilers

Related articles
reg expr... (Shoaib Ali BURQ) (2002-09-08)
Re: reg expr... (Gwyn Judd) (2002-09-11)
Re: reg expr... (Sarah Thompson) (2002-09-11)
Re: reg expr... (Torben Ęgidius Mogensen) (2002-09-12)
| List of all articles for this month |

From: "Torben Ęgidius Mogensen" <>
Newsgroups: comp.compilers
Date: 12 Sep 2002 14:13:20 -0400
Organization: Department of Computer Science, University of Copenhagen
References: 02-09-040 02-09-066
Keywords: lex
Posted-Date: 12 Sep 2002 14:13:20 EDT

"Sarah Thompson" <> writes:

> > I'm looking for a regular expression that say:
> >
> > match the line that does not begin with the string {s}
> >
> For the case where {s} is 'fruitbat', the regex:
> [^f][^r][^u][^i][^t][^b][^a][^t].*|.{0-7}
> should work, assuming the whole input is one line.

Actually, it wont work. The above will reject any string that has 'f'
as first charcter _or_ 'r' as second character, etc., (as long as they
are 8 or more characters long) including things like "funnyfarm" and

Excluding a whole word is more complex. For the "fruitbat" case, I
would write:

[^f].* | "f"[^r].* | "fr"[^u].* | "fru"[^i].* | ... | "fruitba"[^t].*

which can be shortened to

[^f].* | "f"([^r].* | "r"([^u].* | "u"(...([^a]|"a"[^t].*)...)))

I agree that it isn't pretty, but most regexp notations don't allow
negations on strings, only on characters.

Torben Mogensen (

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.