PHP Regular Expression modifier/I,/is,/s,/isU, regular expression isu
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 instance:
/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/I,/is,/s,/isUWhat is it?
I is case insensitive
In s mode, the dot metacharacter (.) matches all characters, including line breaks.
In x mode, white space characters are ignored except escaped characters or in character classes. In addition to the unescaped character classes # And all characters between the next line break, including two headers, are ignored.
If this modifier is set for A (PCRE_ANCHORED), the mode is forced to "anchored", that is, to force matching only from the beginning of the target string, that is, it is automatically added to the beginning of the Mode ^.
D (PCRE_DOLLAR_ENDONLY) If this modifier is set, the dollar character in the pattern matches only the end of the target string. Without this option, if the last character is a line break, the dollar sign will also match before this character (but not before any other line breaks ). If the m modifier is set, ignore this option. Perl does not have an equivalent modifier. S when a mode is used several times, it is worth analyzing for acceleration matching. If this modifier is set, additional analysis is performed. Currently, the analysis mode is only useful for non-anchored modes without a single fixed start character.
U (PCRE_UNGREEDY) This modifier reverses the value of the matching quantity so that it is not the default repetition, but is followed by "?" . This is incompatible with Perl. You can also set in the mode (? U) to enable this option.
X (PCRE_EXTRA) This modifier enables additional features that are not compatible with Perl in a pcre. Any backslash followed by a letter with no special meaning in the mode leads to an error, so that this combination is retained for future expansion. By default, like Perl, a backslash followed by a letter without special meaning is treated as the letter itself. No other features are currently controlled by this modifier. That is: greedy mode. The maximum match is:/a [\ w] +? E/U matches abceade in abceadeddd instead of abce. If U correction is not added, it matches abce u (PCRE_UTF8). This modifier enables an additional feature that is incompatible with Perl in a pcre. The pattern string is treated as a UTF-8. This modifier is available in Unix from PHP 4.1.0 and win32 from PHP 4.2.3.
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.
Who can help me solve the problem? What is the global modifier and g of Regular Expressions in php? It is best to use a small instance to prove it.
If there is no g, only the first matching item is replaced. If yes, all matching items are replaced.
Php Regular Expression
Single quotation marks and/can both be used as regular template delimiters. In fact, # can also be used to facilitate pattern matching. For example, you need to match the content with single quotation marks, in this case, do not use single quotes to enclose the template. Use/or # To simplify the template. Otherwise, you must add an escape character before single quotes in the template.
The end I means case insensitive, Which is case insensitive. s can be understood as full-text matching. That is to say, if the Matching content has a line feed, it is best to add this switch.
In the template, \ s indicates space.
I am a regular expression expert. I have a special book to teach this. You can ask me, QQ1389951.
Give it a score. Haha.