Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java : does regex pattern matcher have a size limit?

Tags:

java

My pattern is OR-like : "word1|word2|word3" I have approximately 800 words.

Can it be a problem ?

like image 600
Johnny Avatar asked Jun 15 '11 13:06

Johnny


2 Answers

You're only limited by memory and sanity. :)

like image 191
vipw Avatar answered Nov 15 '22 05:11

vipw


You might consider using the Aho–Corasick string searching algorithm. It would be much more efficient than a regex, since it's linear and optimized for your problem. It's also a way to pay respect to our fellows from 1975 !

In particular, there is this Java implementation.

like image 35
Remi Mélisson Avatar answered Nov 15 '22 07:11

Remi Mélisson