Is java.util.regexp efficient enough?

I need to do a lot of searches for specific patterns in the source files while the user changes them, so I need to make regular comparisons, effective in time and in memory. The pattern is repeated, so it needs to be compiled once, but I need to be able to extract the parts (and not just confirm the match)

I am considering using java.util.regexp or Jakarta perl5util (if it still exists, it has been several years since I used it) or perhaps the Eclipse search engine, although I doubt it is smarter.

Is there a significant performance difference between the two?

+6
java regex
source share
3 answers

I'm not sure that there is a huge performance gap between the various regexp java engines.

But when building a regular expression (and that is, if the data is large enough, there is a performance problem) noted by Jeff Atwood )

The only thing you should avoid is a catastrophic rollback , it is better to avoid when using the atomic grouping .

So, by default, I would use the java.utils.regexp mechanism if you do not have certain perl-compatible regexp sources that need to be reused in your program.

Then I would carefully construct the regex that I intend to use.

But from the point of view of choosing one engine or another ... since he was told in other questions :

  • "make it work, do it fast - in that order"
  • Beware of "premature optimization."
+9
source share

As VonC says, you need to know your regular expressions. This does not prevent OTHERWISE from compiling Regexes in advance; the cost of compiling a regular expression each time can severely affect performance.

For some categories, alternative libraries exist: http://jint.sourceforge.net/jint.html , which may have better performance. Again, it depends on which version of java you are using.

JDK 1.6 shows the maturity of the regex engine with good features and performance.

+3
source share

In general, the java.util.regex package (not "regexp") is at least as good in any other Java regular expression library, including Jakarta ORO (your "Perl5Util" lib). In addition, it supports both atomic groups and possessive quantifiers, which I find invaluable for writing incredibly fast regular expressions. It also supports precompiled regular expressions and capture groups, but I believe this is true for all libraries.

+2
source share

All Articles