Related articles |
---|
reg expr... shoaib@students.cs.mu.OZ.AU (Shoaib Ali BURQ) (2002-09-08) |
Re: reg expr... gwyn@thislove.dyndns.org (Gwyn Judd) (2002-09-11) |
Re: reg expr... sarah@telergy.com (Sarah Thompson) (2002-09-11) |
Re: reg expr... torbenm@diku.dk (Torben Ægidius Mogensen) (2002-09-12) |
From: | "Torben Ægidius Mogensen" <torbenm@diku.dk> |
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" <sarah@telergy.com> 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
"braggards".
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 (torbenm@diku.dk)
Return to the
comp.compilers page.
Search the
comp.compilers archives again.