Differences between PHP-PCRE and POSIX regular expressions

Source: Internet
Author: User
PHP extension text processing-the difference between PCRE and POSIX regular expressions is from PHP 5.3.0, and POSIX regular expression extensions are discarded. There are some differences between POSIX regular expressions and PCRE regular expressions. This article lists the most significant differences you need to know when switching to PCRE.

The PCRE function requires the mode to be closed with delimiters.

Unlike POSIX, PCRE extensions do not have functions specifically for case-insensitive matching. Instead, you can use the I (PCRE_CASELESS) pattern modifier to perform the same job. Other pattern modifiers can also be used to change matching policies.

The POSIX function looks for the longest match from the left, but the PCRE stops after the first legal match. If the string does not match, there is no difference, but if the string does not match, both results and speeds are different. To illustrate this difference, consider the following example (from Jeffrey Friedl's book Mastering Regular expressions ). Usage mode one (self )? (Selfsufficient )? Match on 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 returns the longest 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 peering function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.