Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does REGEX differ from PHP to Python

Tags:

python

regex

php

I found this post: Python Regex vs PHP Regex but I actually did not get if Python's REGEX syntax matches PHP's REGEX syntax.

I started to convert some of my old PHP code to python (due to g's appengine etc.), and now I would like to know whether the regex is 100% convertable, by simple copy & paste.

regards,

like image 621
Julius F Avatar asked Jun 18 '10 14:06

Julius F


People also ask

Is regex different for different programming languages?

NET's RegEx, and in sum they all scale differently to Python's RegEx. Short answer is "no", although they're likely to be very similar whatever course you're doing, especially in terms of basics (so your course will definitely be applicable).

Are regex same for all languages?

Regular expression synax varies slightly between languages but for the most part the details are the same. Some regex implementations support slightly different variations on how they process as well as what certain special character sequences mean.

Are there different versions of regex?

The syntax and semantics of regexes have been standardized by IEEE as POSIX BRE and ERE . However, there are many non-standard variants. Often, the differences are subtle. Programmers who design regexes must be aware of the variant being used by the engine.

Which language has the best regex?

Java - Java 4 and later include an excellent regular expressions library in the java. util. regex package.


1 Answers

Python uses a syntax similar to the Perl syntax and PHP uses the Perl Compatible Regular Expressions syntax, so it should be nearly the same. Read about the possible differences.

The only real difference is that in PHP, the expression must be enclosed in delimiters.

like image 137
Felix Kling Avatar answered Oct 02 '22 14:10

Felix Kling