Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Summary of differences in regular expression syntax for various tools and languages?

Tags:

regex

grep

I can never remember the differences in regular expression syntax used by tools like grep and AWK, or languages like Python and PHP. Generally, Perl has the most expansive syntax, but I'm often hamstrung by the limitations of even egrep ("extended" grep).

Is there a site that lists the differences in a concise and easy-to-read fashion?

like image 522
yukondude Avatar asked Aug 22 '08 19:08

yukondude


People also ask

Are regular expressions different in different languages?

Some regexes will compile in two different programming languages, but will have different match behavior. For example, the notation /\Q… \E/ will quote the text in between the \Q and \E in Java, PHP, Go, and Perl, but in JavaScript, Ruby, and Python these symbols will be treated as the literals Q and E.

What is the syntax for regular expression?

(dot) Matches any single character, except a new line. Note: Regular expressions in Content Compliance policies are case sensitive. Note: Regular expressions in Content Compliance policies are case sensitive.

Is regex syntax the same across languages?

Though most regexes compile across language boundaries, 15% exhibit semantic differences across lan- guages and 10% exhibit performance differences across languages. We explained these differences using regex documentation, and further illuminate our findings by investigating regex engine im- plementations.

What are different types of regular expression?

There are also two types of regular expressions: the "Basic" regular expression, and the "extended" regular expression.


2 Answers

For my own future reference, I'll offer the Regexp Syntax Summary page which contrasts the syntax for grep, egrep, Emacs, Perl, Python, and Tcl. As expected, Perl supports the greatest variety of operators, but Python looks equally capable, if not more so.

like image 144
yukondude Avatar answered Sep 30 '22 19:09

yukondude


Mastering Regular Expressions, devotes the last four chapters to Java, PHP, Perl, and .NET. One chapter for each. From what I know, the pocket edition contains just those final four chapters.

like image 24
Kibbee Avatar answered Sep 30 '22 19:09

Kibbee