Perl regular expressions are implemented in PHP. We need to use PCRE-related regular expression functions. So what are the specific functions? Here we introduce 4 to you, hoping to be helpful to you.
Introduction to functions used in the implementation of Perl regular expressions in PHP:
1. preg_match:
Function format :
<ol class="dp-c"><li class="alt"><span><span>int preg_match(string pattern, string subject, </span><span class="keyword">array</span><span> [matches]); </span></span></li></ol>
This function will use pattern expression in string to match. If [regs] is given, the string will be recorded in [regs][0], [regs][1 ] represents the first string recorded using brackets "()", [regs][2] represents the second string recorded, and so on. preg will return "true" if a matching pattern is found in string, otherwise it will return "false".
2. preg_replace:
Function format:
<ol class="dp-c"><li class="alt"><span><span>mixed preg_replace(mixed pattern, mixed replacement, mixed subject); </span></span></li></ol>
This function will replace all strings in string that match the expression pattern Replacement for the expression. If the replacement needs to contain some characters of the pattern, you can use "()" to record it. In the replacement, you just need to use "