Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 735
Amitd Avatar asked Oct 16 '10 17:10

Amitd


2 Answers

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

  • It now supports lookbehind assertions, even unbounded ones.
  • Unicode property escapes have been added.
  • There finally is a DOTALL (/s) flag.

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.

like image 160
Tim Pietzcker Avatar answered Sep 22 '22 18:09

Tim Pietzcker


This comparison will answer all your queries.

like image 39
codaddict Avatar answered Sep 20 '22 18:09

codaddict