PHP regular expression matching summary the PCRE pattern is a PHP regular expression matching rule.
It must be enclosed by delimiters (separators can be any non-alphanumeric, non-backslash, and non-blank characters), which means preg_macth ("[\ w {2, 3}]", $ subject) this type of regular match is also possible. Of course, the common type is/\ w {2, 3}/. when there are too many backslashes to escape, you can use other types of delimiters to close the package.
For example,/http: \/\ // can be written as @ http: //. This can also be matched with the name starting with http. After the separator ends, you can add a pattern modifier (the pattern modifier is actually an enhancement of the matching function. for example, if I is set, it will be case insensitive. m is used for multi-row Matching. s-point does not match the line break symbol)
Basic regular expression usage summary: (the most commonly seen matching)
\ Used to escape the backslash. it is required to match the backslash \\
[Abc] {} matches a string of 2 to 5 lengths consisting of any letter in abc.
{^ 123 $} m matches the row at the beginning and end of 123
Equivalent use of the three strings:
* = {0 ,}
+ = {1 ,}
? = {0, 1}
The following is an example of preg_replace ($ pattern, $ replace, $ subject) matching (in reality, regular expression matching is more complex than syntax)
1. group call for regular expression matching
2. remove unnecessary space regular match \ s to match a space character \ s + to match a space string +
$ Str = preg_replace ('/\ s +/', '', $ str );
3. use matched groups (you can enter various possible matching regular expressions in the regular array and use the latter one for replacement)
Preg_replace (array ('/\ d/', '/\ s/'), '*', $ str );
4 .? : The usage of a symbol does not match until a string ends.
Preg_replace ("/(? : <)(.*)(? :>)/I ", $ str, $ result );
Replace the content in <> with $ str at the same time.
Aaa Cdc matches bbb.