Home >Backend Development >PHP Tutorial >PHP—The difference between PCRE and POSIX regular expressions
As of PHP 5.3.0, POSIX regular expression extensions are deprecated. There are some differences between POSIX regexes and PCRE regexes, and this article lists the most significant differences to know when switching to PCRE.
The PCRE function requires the pattern to be closed with a delimiter.
Unlike POSIX, the PCRE extension does not have dedicated functions for case-insensitive matching. Instead, support uses the i (PCRE_CASELESS) mode modifier to accomplish the same job. Other pattern modifiers can also be used to change the matching strategy.
POSIX functions look for the longest match starting from the left, but PCRE stops after the first legal match. It makes no difference if the strings don't match, but if they do, there will be a difference in results and speed. To illustrate this difference, consider the following example (from Jeffrey Friedl's book Mastering Regular Expressions). Using the pattern one(self)?(selfsufficient)? to match the string oneselfsufficient, PCRE will match oneself, but with POSIX, the result will be the entire string oneselfsufficient. Both substrings match the original string, but POSIX treats the longest as the result.
Function comparison table
POSIX
PCRE
ereg_replace() preg_replace()
ereg() preg_match()
eregi_replace() preg_replace()
eregi() preg_match()
split () preg_split()
spliti() preg_split()
sql_regcase() No equivalent function