Note:
Backslashes have special meanings in both single-quote strings and double-quote strings, so to match a backslash, the pattern must be written as "\\\\". "/\\/", first it as a string, the backslash will be escaped, then the result of escaping is/\/, this is the regular expression engine to get the pattern, and the regular expression engine also think \ is an escape token, it will be the delimiter/escaped, resulting in an error, so it takes 4 backslashes to Can match a backslash.
In fact
$attribute = "sdfsdf.555";p reg_match ('/([\w]+) (\.) ([0-5]|.) /', $attribute, $matches); Array ( [0] = sdfsdf.555 //Match ([\w]+) (\.) ([0-5]|.) If the entire pattern match fails, the match will not continue. For example $attribute = "sssss555" [1] = = SDFSDF //Match (\w+) [2] = =. Match (\.) [3] = = 555 //Match ([0-5]*))
Preg_replace_callback
Each value that is matched to a character channeling expression is processed and returned with a callback function:
The function will continue searching after the first match.
The first match gets [{summary}]
Then it continues to search for matches to get [{items}]
Last match to get [{form}]
The next example: Regular Expressions: The results of the match were: [{Summary}],[{items}] [{form}]
Use three values for a callback function ...
Compare the differences between the following two matching values:
$layout = "{summary}\n{items}\n{form}"; $content = Preg_replace_callback ("/{\\w+}/", function ($matches) {Print_r ($ matches); return $matches [0];}, $layout);p Rint_r ($content); $layout = "{summary}-{items}-{form}"; $content = Preg_replace_ Callback ("/({\\w+}) (-)/", function ($matches) {print_r ($matches);//["{summary}-", "{Summary}", "-"]return $matches [0 ], $layout);p Rint_r ($content);
PHP preg Regular Expressions