36

Are Python and JavaScript regular expression syntax identical?

If not, then:

  1. What are the important differences between them
  2. Is there a python library that "implements" JavaScript regexps?
Chad Birch
  • 69,230
  • 22
  • 145
  • 148
Dave Peck
  • 1,312
  • 1
  • 17
  • 24

3 Answers3

31

There is a comparison table here:

Regex Flavor Comparison

Bernhard Barker
  • 50,899
  • 13
  • 85
  • 122
EBGreen
  • 33,707
  • 11
  • 58
  • 80
  • Thanks! My attempts at googling the answer failed. Now, I guess the follow up question is: "Is there a python library that 'implements' javascript regexps?" – Dave Peck Mar 11 '09 at 21:59
  • I don't know of one. What is the root reason for wanting one? – EBGreen Mar 12 '09 at 13:14
  • 9
    I'd like a Python library compatible with EMCA regex because I want consistency between a regex search in Python on the back-end and a Javascript one on the front-end. – Brian M. Hunt Jul 06 '10 at 14:05
  • 2
    The link point to TOC now. Wikipedia has some resources on the subject: https://en.wikipedia.org/wiki/Comparison_of_regular_expression_engines – Vajk Hermecz May 30 '16 at 16:03
  • 3
    The link isn't useful anymore. It would have been better to answer the question directly. – Akh Sep 06 '16 at 00:05
7

Part 1
They are different; One difference is Python supports Unicode and Javascript doesn't.

Part 2
Read Mastering Regular Expressions. It gives information on how to identify the back-end engines (DFA vs NFA vs Hybrid) that a regex flavour uses. It gives tons of information on the different regex flavours out there.

There is way too much information to convey on a single SO answer, so you're better off having a solid piece of reference material on the subject.

Gavin Miller
  • 40,636
  • 19
  • 113
  • 178