Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's different between Python and Javascript regular expressions?

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?
like image 697
Dave Peck Avatar asked Mar 11 '09 21:03

Dave Peck


People also ask

Is regex different from Python?

Python supports essentially the same regular expression syntax as Perl, as far as the regular expressions themselves. However, the syntax for using regular expressions is substantially different. Regular expression support is not available out of the box; you must import the re module.

Is regex different for different programming languages?

Each different programming language will offer a function or method to run this validation. Often it's named something along the lines of matches and will return true if the pattern matches and false if not. This pattern is the same for all programming languages that implement Regular Expressions.

Does Python use regex?

Regex is provided by many programming languages, such as python, java, javascript, etc.

What are the benefits of regex regular expressions in Python?

A Regular Expression is used for identifying a search pattern in a text string. It also helps in finding out the correctness of the data and even operations such as finding, replacing and formatting the data is possible using Regular Expressions.


2 Answers

There is a comparison table here:

Regex Flavor Comparison

like image 121
EBGreen Avatar answered Oct 05 '22 13:10

EBGreen


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.

like image 26
Gavin Miller Avatar answered Oct 05 '22 13:10

Gavin Miller