aspose file tools*
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
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: 8186
    
  23

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to regexes with negations / exceptions