Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > negating words with Java regular expressions

Reply
Thread Tools

negating words with Java regular expressions

 
 
Raj Ashar
Guest
Posts: n/a
 
      07-13-2004
All, I would like to know if Java's implementation of regular
expressions allows for the negation of a word. I know that it is
possible to negate members of a character class with "[^...]" to avoid
matching against those characters, and that it is possible to match
for a string by specifying the members of the string in a regular
expression (eg "my first regex"), but I'm not sure if there's a way to
match selectively (ie match all instances of ";" except where ".;.").

Thank you.

Raj
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      07-13-2004
Raj Ashar wrote:
> but I'm not sure if there's a way to
> match selectively (ie match all instances of ";" except where ".;.").


Pattern.compile("[^\\.]\\;[^\\.]");

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
 
Carl Howells
Guest
Posts: n/a
 
      07-13-2004
Chris Smith wrote:
> Raj Ashar wrote:
>
>>but I'm not sure if there's a way to
>>match selectively (ie match all instances of ";" except where ".;.").

>
>
> Pattern.compile("[^\\.]\\;[^\\.]");
>


Nope. That won't do. You're matching all instances of
"<something>;<something>", except when both <something>s are ".". But
that isn't what was requested. That won't match either semicolon in the
string "; hello! ;", for instance. It also grabs the characters on
either side of the semicolon, which is not what was requested, either.

Try:

Pattern.compile("(?<!\\.);(?!\\.)");

I haven't tested it, but it should work.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking that user has entered a word or words in text input form using regular expressions... Luke Matuszewski Javascript 8 04-22-2006 07:47 AM
Negating a regular expression kwest Perl Misc 12 11-18-2005 07:50 PM
Negating values for cell total Katie Computer Support 8 09-13-2005 08:13 PM
Negating a List Of Numbers Eduardo Bezerra C++ 19 04-20-2005 08:07 AM
Add custom regular expressions to the validation list of available expressions Jay Douglas ASP .Net 0 08-15-2003 10:19 PM



Advertisments