Cap'n Steve has asked for the wisdom of the Perl Monks concerning the following question:

Perl has basically become the grandfather of all regular expressions. I know it wasn't the first, but it's either the best implemented or most well known, so every other language that I've seen compares their regular expressions to Perl's.

What I'm looking for is some reference that lists all the differences between regular expressions in various languages (particularly Javascript) and Perl. I've been searching for the solution for ages, but so far all I've found is a decent, if brief, reference in the O'Reilly PHP book.
  • Comment on Slightly Off Topic: Differences with Regular Expressions in other languages

Replies are listed 'Best First'.
Re: Slightly Off Topic: Differences with Regular Expressions in other languages
by Corion (Patriarch) on Jan 09, 2006 at 08:33 UTC

    If you're interested in the details of differences between the various engines for regular expressions, I really recommend Jeffrey Friedl's Mastering Regular Expressions. That other website also has other stuff I see and is not only centered about the book. I guess that on the Tools, Utilities and Programming Languages page there is a comparison somewhere.

    Update: I fell for a slight variation in the URL - http://regex.info/, Jeffrey Friedl's site is about the book which I recommend, while http://regexp.info is some more generic regular expression site.

      That site as well as the Sun page has some interesting information, but it's still fairly incomplete. According to regexp.info, Javascript only supports /gim modifiers, but there's no mention of most other features.

      What actually started this quest was me wondering if the \Q \E method of escaping was supported. I doubt it is, but it'd be nice to know for sure.
Re: Slightly Off Topic: Differences with Regular Expressions in other languages
by inman (Curate) on Jan 09, 2006 at 11:26 UTC
    My untested assumption is that JavaScript inherits it's RegEx behaviour from the Java API. The documentation for the java.util.regex.Pattern class includes a section that describes the differences from Perl 5. This may be of help.

      I don't think that's right, because Javascript had regular expressions as of version 1.2, which I believe came out in 1999, whereas Java did not have an official Regexp API until J2SE 1.4 which came out in 2002. So I believe JS took its cue directly from Perl. This document from Sun seems to be a definitive reference.

      Update: One other hint is the fact that Javascript uses an identical syntax to Perl for specifying literal regexps (//) and modifiers, but Java does everything through objects.

Re: Slightly Off Topic: Differences with Regular Expressions in other languages
by sub_chick (Hermit) on Jan 09, 2006 at 23:58 UTC
    I also heard recently that the vim editor is adding more support for regexes with a few differences from perl's regexes. Is this so?


    Es gibt mehr im Leben als Bücher, weißt du. Aber nicht viel mehr. - (Die Smiths)"