38

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
  • 73,098
  • 23
  • 151
  • 149
Dave Peck
  • 1,342
  • 1
  • 17
  • 24

3 Answers3

32

There is a comparison table here:

Regex Flavor Comparison

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
EBGreen
  • 36,735
  • 12
  • 65
  • 85
  • 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
  • 11
    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
  • 4
    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
  • 43,168
  • 21
  • 122
  • 188