When using regular expressions in PHP, there are some differences from other languages, one of which is that PHP has a regular modifier (qualifier).
We encounter modifiers in the learning of PHP regular expressions, so what do we need to note about the understanding and use of the PHP regular expression modifiers? So let's take a concrete look at its concept and its content. Before learning the PHP regular expression modifier, first to understand the greedy mode, before the meta-character mentioned in the "?" There is also an important role, namely "greedy mode", what is "greedy mode"?
PHP Regular Expression greedy mode:
For example, we want to match the letter "a" at the beginning of the letter "B" end of the string, but need to match the string after "a" contains a lot of "B", such as "a bbbbbbbbbbbbbbbbb", that the regular expression will match the first "B" or the Last "B"? If you use greedy mode, it will match to the last "B", and vice versa only to the first "B".
PHP Regular Expression Greedy pattern usage example:
- /a.+?b/
- /a.+b/u
The comparison of instances that do not use greedy mode is as follows:
- /a.+b/
The above uses a modifier u, see the description of the modifier.
The understanding of the PHP regular expression modifier:
Modifiers in a regular expression in PHP can change many of the regular features, making regular expressions more appropriate for your needs (note: Modifiers are sensitive to capitalization, which means "E" is not equal to "E").
The type and description of the PHP regular expression modifier:
- I: If you add "I" to the modifier, the regular will remove the case sensitivity, i.e. "a" and "a" are the same.
- M: Default regular start "^" and end "$" just for regular strings if you add "M" to the modifier, then the start and end will refer to each line of the string: the beginning of each line is "^" and the End is "$".
- S: If "s" is added to the modifier, then the default "." Any character that represents anything other than a newline character will become any characters, including line breaks!
- x: If the modifier is added, the white space character in the expression will be ignored unless it has been escaped.
- E: This modifier is only useful for replacement, and represents the PHP code in replacement.
- A: If you use this modifier, the expression must be the beginning of the matching string. For example, "/a/a" matches "ABCD".
- E: In contrast to "M", if this modifier is used, then "$" will match the end of the absolute string, not the line break, which is turned on by default.
- U: Similar to question mark, used to set "greedy mode".
The relevant contents of the PHP regular expression modifier are introduced to you here, hoping to help you understand and master the PHP regular expression modifiers.
http://www.bkjia.com/PHPjc/752344.html www.bkjia.com true http://www.bkjia.com/PHPjc/752344.html techarticle when using regular expressions in PHP, there are some differences from other languages, one of which is that PHP has a regular modifier (qualifier). We are in the PHP regular expression of ...