Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do RE2-like regular expression library for Java exist?

Tags:

java

regex

re2

Did anyone come across Java version of Google's regular expression library RE2 or a java library with similar capabilities and good performance? The performance requirement is linear time with regard to the length of regular expression and the input text length.

Clarification

Most regular expression implementation use a backtracking algorithm to match the input text and hence are exponential on some simple regular expressions like (.*).(.*).(.*).(.*). RE2 is a library from google that solves this problem by using an algorithm that varies linearly with input size using the concepts of Automata theory. The questioner wants to know whether there exists libraries for Java that are based on this algorithm.

like image 327
depthofreality Avatar asked Aug 20 '11 21:08

depthofreality


People also ask

Does Java use regex?

Regular Expressions or Regex (in short) in Java is an API for defining String patterns that can be used for searching, manipulating, and editing a string in Java. Email validation and passwords are a few areas of strings where Regex is widely used to define the constraints. Regular Expressions are provided under java.

What is re2j?

RE2/J: linear time regular expression matching in Java RE2 is a regular expression engine that runs in time linear in the size of the input. RE2/J is a port of C++ library RE2 to pure Java.


1 Answers

Google today released a pure-Java port of Go's RE2 implementation. You can find it here:

https://github.com/google/re2j

like image 71
Alan Donovan Avatar answered Sep 19 '22 18:09

Alan Donovan