tags:

views:

86

answers:

3

Are regular expressions the same for PHP, MySQL, JavaScript, Perl, and so on? If so, is there a chart or tutorial that explains regular expressions?

+7  A: 

No, there often are subtle differences in supported features (mostly of the pretty advanced kind1). For example, JavaScript regular expressions don't have lookbehind. PHP uses either POSIX extended regular expressions or PCRE (Perl-compatible regex), which are close to Perl's feature-set. In fact, Perl is probably the ancestor of many advanced features in today's regular expression engines.

As for tutorials and comparisons the site http://regular-expressions.info is a very good resource.

Once you got used to writing and applying them it often is helpful to just quickly try out things. I have found a REPL to be quite handy; I usually use Windows PowerShell but Ruby or Python are also pretty popular.


1 Thanks, Dancrumb.

Joey
+1 http://regularexpressions.info is a god-send. One of the best sites to learn RegEx's that I've found.
Jonathan Sampson
+1 for the answer; but I'd add that the differences are usually in the *advanced* features of regular expressions. regularexpressions.info will help you understand what's advanced and what's basic.
Dancrumb
@Dan: Agreed. However, I've also seen things like lazy quantifiers not work (Notepad++ ...) which I consider pretty basic. But yes, the usual greedy quantifiers, string literals, character classes and alternatives are probably supported by pretty much any implementation, including `findstr` on Windows :-)
Joey
A: 

In theory regular expression is a language for pattern matching.But there are little differences from language to language . My advice is use a tool like Regex Coach to building/learning regular expressions.

Upul
A: 

There is an excellent write-up of Perl regular expressions compared to "classic", POSIX and GNU grep in Chapter 3 of the book "Minimal Perl" by Tim Maher. And I think it's a good read for any of them, not just Perl.

And what do you know, "Sample Chapter 3" is available as a download from this page: Minimal Perl book!

Jim Flood