tags:

views:

71

answers:

1

Does Java perform any regex optimisations; if so, what are they?

I'm interested in both optimisations at the regex engine level, and more general usage-level optimisations.

(For example, in some other languages, commonly used regexes are cached to avoid re-compiling, but what I've read so far implies that Java doesn't do this automatically?)

To be clear:
I'm not asking for how to optimise the actual regular expressions themselves. I'm asking about actions that might happen automatically, inside the regex engine.

+2  A: 

According to the source code for java.util.regex.Pattern, the compile() method doesn't attempt any cache optimizations.

Near the end, there is a code comment that points out the use of peephole optimization.

Gunslinger47