Skip to main content

Optimizing regular expressions in Java - Java World

Popularity Report

Total Popularity Score: 0

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Rank

Bookmark History

Saved by 2 people (0 private), first by anonymouse user on 2008-07-28


Public Sticky notes

If you will use a regular expression more than once in your program, be sure to compile the pattern using Pattern.compile() instead of the more direct Pattern.matches().

Highlighted by benxshen

Also remember that you can re-use the Matcher object for different input strings by calling the method reset().

Highlighted by benxshen

If you don't really need to capture the text inside a group, always use non-capturing groups. For example, use "(?:X)" instead of "(X)".

Highlighted by benxshen