Related articles |
---|
negating words with Java regular expressions Raj.Ashar@jhuapl.edu (2004-07-13) |
Re: negating words with Java regular expressions amit_shanbhag@yahoo.com (=?iso-8859-1?q?Amit=20Shanbhag?=) (2004-07-13) |
From: | =?iso-8859-1?q?Amit=20Shanbhag?= <amit_shanbhag@yahoo.com> |
Newsgroups: | comp.compilers |
Date: | 13 Jul 2004 22:33:14 -0400 |
Organization: | Compilers Central |
References: | 04-07-019 |
Keywords: | lex |
Posted-Date: | 13 Jul 2004 22:33:14 EDT |
In regular expressions
If you are looking for ";" not preceeded by a number
you could do it with the zero-width negative look
behind operators.
For your particular case, this would be.
(?![0-5]*);
This will look for numerical characters preceeding a
";", -->this is called look behind
the search will be negated "(?! )" ---> hence negative
The matching string will always only return ";" or
nothing at all. ie the pattern "[0-5]*" will never
contribute any chanracter to the resultant match-->
hence zero-width
For more info look at
http://www.regular-expressions.info/
regards
-amit shanbhag
--- Raj Ashar <Raj.Ashar@jhuapl.edu> wrote: > All, is
there a way to negate words using regular
> expressions as
> implemented by Java? I know that one can negate the
> characters in a
> character class using the caret ([^a-z]), but I
> would like to build
> expressions of the form:
>
> Match ";" and not "5;".
>
> Though one can match strings positively (as in match
> against string
> "abc"), there does not appear to be a simple way to
> indicate negative
> matches (do not match "abcd").
Return to the
comp.compilers page.
Search the
comp.compilers archives again.