aspose file tools
The moose likes Java in General and the fly likes Class Pattern - regular expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Class Pattern - regular expressions" Watch "Class Pattern - regular expressions" New topic
Author

Class Pattern - regular expressions

Dar Var
Ranch Hand

Joined: Oct 12, 2004
Posts: 74
Hi
I have a few regular expressions that each work seperately i.e. each find the strings that contain the its pattern. However I want to create an expression that is a combination of them all. Thus this new totalPattern will check if the string contains % at the beginning or end
but does not contain \% at the end



Therefore the code will output:

%
test%
%test
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Looks like you 'borrowed' one of my other regex posts! I think the following does what you want



Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Dar Var
Ranch Hand

Joined: Oct 12, 2004
Posts: 74
Thanks James,
Borrowed that alright! Good stuff.

Can you tell me what book or site you used to learn this?
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Can you tell me what book or site you used to learn this?


1) Mastering Regular Expression, Jeffrey E. F. Friedl, published by O'Reilly.

My copy is a bit dated now and does not contain topics such as 'negative look behind'. I know there is a new edition but I don't know if it contains 'negative look behind'.

2) Programming Perl, Wall, Christiansen & Schwartz, published by O'Reilly.

I cut my teeth on this when I first learned Perl and Perl without regex is a eunuch.

3) The Javadoc for java.util.regex.Pattern.

4) The SUN Java developer forums where regex questions come up fairly frequently. Each time I find a regex problem posted that I can't deal with I study the responses and make sure I understand them.

5) Google for the various regex tutorials.
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
Also, there's a good tutorial at

http://www.regular-expressions.info/

The second edition of Friedl's book does cover negative lookbehind, plus other new goodies like atomic groups and possessive quantifiers. And it has a chapter devoted to Java.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Class Pattern - regular expressions
 
Similar Threads
Finding a pattern in a String
Problems with Matcher objects and the last line of a file
Alternative to String.split()
Regular Expressions on a .csv file
Regular Expressions: A String should not contain the word "TEST"