Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between perl and java regex capabilities?

What are the differences between perl and java with regard to what regular expression terms are supported?

This question is isolated to just the regular expressions, and specifically excludes differences in how regex can be used - ie the functions/methods available that use regex - and syntactic differences between the languages such as the java requirement to escape backslashes etc.

Of particular interest is the partial/occasional support java has for variable length look-behinds.

like image 363
Bohemian Avatar asked Dec 25 '12 11:12

Bohemian


People also ask

What regex does Perl use?

Perl uses Perl regular expressions, not POSIX ones. You can compare the syntaxes yourself, for example in regex(7) .

What is java regex used for?

Regular expressions can be used to perform all types of text search and text replace operations. Java does not have a built-in Regular Expression class, but we can import the java. util. regex package to work with regular expressions.

Which regex engine does java use?

Java Regex API provides 1 interface and 3 classes in java. util. regex package.

Are regex same java and JavaScript?

There is a difference between Java and JavaScript regex flavors: JS does not support lookbehind. A tabulation of differences between regex flavors can be found on Wikipedia. However, this does not apply to your case.


1 Answers

The "Comparison to Perl 5" section of java.util.regex.Pattern lists many differences. For example, Java does not support conditional regex. For that, you need to use some external library like JRegex.

like image 86
Rohit Jain Avatar answered Nov 01 '22 05:11

Rohit Jain