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!