Home >Backend Development >PHP Tutorial >Example introduction to PHP regular expression modifiers

Example introduction to PHP regular expression modifiers

零下一度
零下一度Original
2017-07-25 11:51:141328browse

◆i: If "i" is added to the modifier, the regular expression will cancel the case sensitivity, that is, "a" and "A" are the same.
◆m: The default regular start "^" and end "$" are only for regular strings. If "m" is added to the modifier, then the start and end will refer to each line of the string: each line The beginning is "^" and the end is "$".
◆s: If "s" is added to the modifier, the default "." representing any character except the newline character will become any character, including the newline character!
◆x: If this modifier is added, whitespace characters in the expression will be ignored unless it has been escaped.
◆e: This modifier is only useful for replacement, which means it is used as PHP code in replacement.
◆A: If this modifier is used, the expression must be the beginning of the matched string. For example, "/a/A" matches "abcd".
◆E: Contrary to "m", if this modifier is used, then "$" will match the end of the absolute string, not before the newline character. This mode is turned on by default.
◆U: Similar to the question mark, used to set "non-greedy mode".

Case:

"a bbbbbbbbbbbbbbbbb"
/a.+?/   匹配到a 
/a.+/U   匹配到a 
/a.+/    匹配到a bbbbbbbbbbbbbbbbb

So when U is set + the default greedy matching becomes non-greedy matching

The above is the detailed content of Example introduction to PHP regular expression modifiers. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn