Javascript regex compared to Perl regex

I'm just a noob when it comes to regexp. I know Perl is amazing with regexp and I don't 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) written in JS be used in Perl and vice-versa? Similar syntax?


From ECMAScript 2018 onwards, many of JavaScript's regex deficiencies have been fixed.

What is still missing:

  • JavaScript doesn't have a way to prevent backtracking by making matches final (using possessive quantifiers ++/*+/?+ or atomic groups (?>...)).
  • Recursive/balanced subgroup matching is not supported.
  • One other (cosmetic) thing is that JavaScript doesn't know verbose regexes, which might make them harder to read.

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

This comparison will answer all your queries.

Another difference: In JavaScript, there is no s modifier: The dot "." will never match a newline character. As a replacement for ".", the character class [\s\S] can be used in JavaScript, which will work like /./s in Perl.

I just ran into an instance where the \d, decimal is not recognized in some versions of JavaScript -- you have to use [0-9].

Need Your Help

Usage of integers as hash keys

ruby hashmap

Is it appropriate to use integers as keys in a Ruby hash?

How can I read lines from the end of file in Perl?

perl large-files

I am working on a Perl script to read CSV file and do some calculations.