The editor below will bring you a cliché about what i, m, s, x, and e in php regular expressions represent respectively. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor to take a look.
i
If this modifier is set, the characters in the pattern will match both uppercase and lowercase letters.
m
When this modifier is set, "line start" and "line end" will match the beginning and end of the entire string. Also matches after and before newline characters.
s
If this modifier is set, the dot metacharacter (.) in the pattern matches all characters, including newlines. Without this setting, newline characters are not included.
x
If this modifier is set, whitespace characters in the pattern are completely ignored except those that are escaped or within a character class , all characters between # outside the unescaped character class and the next newline character, inclusive, are also ignored.
e Replace, ? after . + and * to indicate a non-greedy match: The *, +, and ? qualifiers are all greedy in that they will match as many literals as possible, only with one after them ?You can achieve non-greedy or minimum matching. For example:
<?php $string = "上飞机离开我<img border='0' alt='' src='/uploadfile/2009/0921/20090921091612567.jpg' border='0' />sdfsdf"; $su = preg_match("/ \<[ ]*img.*src[ ]*\=[ ]*[\"|\'](.+?)[\"|\'] /", $string,$match); // 匹配src=的内容 print_r($match[1]); // 输出 /uploadfile/2009/0921/20090921091612567.jpg $su = preg_match("/ \<[ ]*img.*src[ ]*\=[ ]*[\"|\'](.+)[\"|\'] /", $string,$match); print_r($match[1]); // 输出 /uploadfile/2009/0921/20090921091612567.jpg' border=' ?>
Example: (?i):
##(?i) means internal modifier in PHP, i means case-insensitive
Other modifiers include x, m, s, U, etc. It's the same pattern modifier we used. The difference is that it is used inside the pattern. It only works within the sub-pattern where (?i) is located.
Such asccc(a(?i))bcd 匹配 cccabcd和cccAbcd
and a(?i)bc is the same as abc plus the \i modifier Because (?i) acts on the entire pattern
Backreference
Adding parentheses around a regular expression pattern or part of a pattern will cause the associated matches to be stored in A temporary buffer in which each captured submatch is stored from left to right as encountered in the regular expression pattern. The buffers in which submatches are stored are numbered starting from 1 and numbered consecutively up to a maximum of 99 subexpressions. Each buffer can be accessed using '\n', where n is a one- or two-digit decimal number that identifies a particular buffer.
You can use the non-capturing metacharacters '?:', '?=', or '?!' to ignore the preservation of related matches. The above is a brief discussion of what i, m, s, x, and e in PHP regular expressions represent. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!