Re: negating words with Java regular expressions

=?iso-8859-1?q?Amit=20Shanbhag?= <>
13 Jul 2004 22:33:14 -0400

          From comp.compilers

Related articles
negating words with Java regular expressions (2004-07-13)
Re: negating words with Java regular expressions (=?iso-8859-1?q?Amit=20Shanbhag?=) (2004-07-13)
| List of all articles for this month |

From: =?iso-8859-1?q?Amit=20Shanbhag?= <>
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.

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

-amit shanbhag

--- Raj Ashar <> 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").

Post a followup to this message

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