This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes How to regexes with negations / exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to regexes with negations / exceptions" Watch "How to regexes with negations / exceptions" New topic
Author

How to regexes with negations / exceptions

Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
Hi All,

I need your help to advice on how to include a few exceptions from the following regexes:

I can use multiple Java string matches and combine them with booleans to achieve the same objectives but would like to find out how the regexes work on their own.

Thanks in advance,

Jack
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7696
    
  20

Jack Bush wrote:I can use multiple Java string matches and combine them with booleans to achieve the same objectives but would like to find out how the regexes work on their own.

Then my suggestion would be to find a good tutorial. I'm a reasonably advanced regex user (old Unix sysadmin), and even I would tackle this in stages:
1. Get your "words".
2. Run much simpler regexes against each word.

The trouble with trying to do it all at once is that you're likely to end up with a huge (and extremely arcane) expression that has to be documented
for the next poor soul who has to look at your code - which may be you in a few years time when you've forgotten what you were trying to do.

Winston

BTW - Could you possibly reduce the line length on your posts? It's a bit of a pain having to scroll backwards and forwards constantly.
Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
Thanks for this valuable advice Winston,

I need to strike the balance between keeping the codes simple for ease of maintenance while trying
to exploit the power of regex.

Jack
 
Don't get me started about those stupid light bulbs.
 
subject: How to regexes with negations / exceptions