Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StringUtils.contains of Apache and Boyer–Moore string search algorithm

To search for s in S (size(S) >= size(s) and return a true/false value), it's better for performance to use StringUtils.contains() of Apache or use Boyer-Moore algorithm implemented and tested well by someone I found?

Thanks

like image 482
xuongrong Avatar asked Feb 14 '23 16:02

xuongrong


1 Answers

The last time I looked into the Java regex matching code while debugging, the Java 7 regex engine used the Boyer-Moore algorithm for sequences of literal text matches. So the easiest way to find a String using Boyer-Moore is to prepare using p=Pattern.compile(searchString, Pattern.LITERAL) and search using p.matcher(toSearchOn).find(). No third party libraries and no handcrafted work needed. And I believe the JRE classes are tested well…

like image 189
Holger Avatar answered Feb 17 '23 07:02

Holger