POSIX Extended Regular expression functions

Source: Internet
Author: User
Tags ereg
Searching strings is the main application of regular expressions. In PHP, the two functions that can be used to match POSIX regular expressions are ereg () and eregi. The syntax format of ereg () and eregi () functions is as follows: finding strings is the main application of regular expressions. In PHP, the two functions that can be used to match POSIX regular expressions are ereg () and eregi.

Ereg () and eregi () functions

The syntax of the function is as follows:

Int ereg (string pattern, string search, array [matches]);

Function: This function searches for the string search and finds the string matching the regular expression in pattern. If a string matches the child expression of pattern, the strings are stored in the array matches, and each array element corresponds to a subexpression.

Except case-insensitive, the eregi () function is the same as the ereg () function.

The instance shows whether the variable is valid by using the ereg () function:

 

Note: In the new PHP version, ereg has been discarded and replaced by preg_match ().

Ereg_replace () and eregi_replace ()

The syntax of the function is as follows:

String ereg_replace/ereg_replace (string pattern, string replacement, string)

Function: replacement is used to replace the matched string and return the replaced string if the expression pattern is matched successfully. If no match is found in the string, the string is returned as is. Eregi_replace () is case insensitive.

The following example shows how to replace all non-uppercase tm strings with uppercase TM:

 

Note: In the new version, eregi_replace () is replaced by preg_replace.

The above is the details of POSIX Extended Regular expression functions. For more information, see other related articles in the first PHP community!

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.