Parse the PHP regular expression modifier. We will encounter modifiers in PHP Regular Expression Learning. so what do we need to know about PHP regular expression modifiers and how to use them? So let's take a look at it. we will encounter modifiers in PHP Regular Expression Learning. so what do we need to know about PHP regular expression modifiers and how to use them? Let's take a look at its concept and related content. Before learning the PHP regular expression modifier, we should first understand the greedy mode. we mentioned above in the metacharacters "? "Another important role is" greedy mode ". what is" greedy mode?
PHP regular expression greedy mode:
For example, we want to match the string ending with the letter "a" and the letter "B", but the string to be matched contains many "B" after "", for example, "a bbbbbbbbbbbbbbbbb", will the regular expression match the first "B" or the last "B? If you use the greedy mode, it will match the last "B", and vice versa, it will only match the first "B ".
PHP regular expression greedy mode example:
- /a.+?b/
- /a.+b/U
Examples that do not use greedy mode are as follows:
- /a.+b/
The above uses a modifier U. for details, refer to the introduction to modifiers.
PHP regular expression modifier:
Modifiers in PHP regular expressions can change many features of regular expressions, making them more suitable for your needs (note: modifiers are case sensitive, this means that "e" is not equal to "E ").
PHP regular expression modifier types and descriptions:
◆ I: if "I" is added to the modifier, the regular expression will be case insensitive, that is, "a" and "A" are the same.
◆ M: The default regular start "^" and end "$" only if "m" is added to the modifier of the regular string ", the start and end operations refer to each line of the string. each line starts with "^" and ends with "$ ".
◆ S: if "s" is added to the modifier, the default "." indicates that any character except the line break will become any character, that is, include a line break!
◆ X: if this modifier is added, the blank characters in the expression will be ignored unless it has been escaped.
◆ E: This modifier is only useful for replacement, which indicates that it is used as PHP code in replacement.
◆ A: If this modifier is used, the expression must be the start part of the matched string. For example, "/a/A" matches "abcd ".
◆ E: opposite to "m". if this modifier is used, "$" matches the end of an absolute string instead of the line break. this mode is enabled by default.
◆ U: similar to the question mark, used to set "greedy mode ".
The related content of PHP regular expression modifier will be introduced here, I hope to help you understand and master PHP regular expression modifier.
Why? Let's take a look at it...