Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparison of Regex flavours

I wonder if there is a comparison between the features of various regex metacharacters in various implementations.

The sort of thing I am looking for is a table like

Language       Perl    sed
grouping       ( )     \( \)

Languages I am interested in are Perl, Sed Java Javascript

like image 203
justintime Avatar asked Sep 25 '10 14:09

justintime


People also ask

What are the flavors of regular expressions?

Regular expressions (RE), as defined by POSIX, come in two flavors: extended regular expressions (ERE) and basic regular expressions (BRE).

Are there different versions of regex?

As a result, broadly speaking, there are three types of regex engines: DFA (POSIX or not—similar either way) Traditional NFA (most common: Perl, . NET, PHP, Java, Python, . . . )

What flavor of regex does r use?

R supports two regular expression flavors: POSIX 1003.2 and Perl. Regular expression functions in R contain two arguments: extended , which defaults to TRUE , and perl , which defaults to FALSE .

Is regex matching expensive?

Avoid coding in regex if you can In programming, only use regular expressions as a last resort. Don't solve important problems with regex. regex is expensive – regex is often the most CPU-intensive part of a program. And a non-matching regex can be even more expensive to check than a matching one.


2 Answers

There's a comprehensive comparison page here: Regular Expression Flavor Comparison.

Some languages implement a particular style, so look up your language on that page and determine which column to look at. For example, JavaScript will be under ECMA. For sed it depends on whether you're using UNIX or Linux (from the page):

The sed UNIX tool uses POSIX BRE. Linux usually ships with the GNU implementation, which use "GNU BRE".

like image 155
Ahmad Mageed Avatar answered Oct 09 '22 06:10

Ahmad Mageed


The Wikipedia comparison of regular expression engines chart is comprehensive and easy to understand.

There is also Richard Kettlewell's regexp syntax summary.

like image 37
dawg Avatar answered Oct 09 '22 05:10

dawg