views:

113

answers:

2

I'm just a noob when it comes to regexp... I know Perl is amazing with regexp... and I dont know much Perl. Recently started learning JavaScript and came across regex for validating user inputs... haven't used them much.

How does JavaScript regexp compare with Perl regexp? Similarities and differences? Can all regexp(s) wriiten in JS be used in Perl and vice-versa? Similar syntax?

+6  A: 

This comparison will answer all your queries.

codaddict
Except it's about three years out of date, since it only covers Perl 5.8, and several of the things on that list were added in 5.10.
hobbs
@hobbs - some of us still live in the 5.8 world :)
DVK
To be specific (that is, actually helpful), 5.10 adds named captures, named backreferences, and the "possessive quantifiers" using `+`, as well as some other stuff related to backtracking control and recursive-descent parsing that isn't in that comparison.
hobbs
+4  A: 

The most important difference you will encounter in real life is JavaScript's lack of lookbehind assertions.

Then, JavaScript doesn't have a way to prevent backtracking by making matches final (using possessive quantifiers ++/*+/?+ or atomic groups (?>...)).

Furthermore, JavaScript doesn't know Unicode properties/scripts/blocks.

Other than that, the basic regex syntax is very similar in both flavors.

One other (cosmetic) thing is that JavaScript doesn't know verbose regexes, which might make them harder to read.

Tim Pietzcker