Introduction of PHP regular expressions and i and is and s and isU etc.

  • 2021-07-22 09:16:11
  • OfStack

What are the PHP regular expressions/i,/is,/s,/isU, and so on?

i is case insensitive

The dot metacharacter (.) in s pattern matches all characters, including newline characters

Whitespace characters in x mode are completely ignored except those escaped or in character classes, and all characters between # and the next 1 newline character except unescaped character classes, including both ends, are also ignored

A (PCRE_ANCHORED) If this modifier is set, the pattern is forced to be "anchored", which forces a match only from the beginning of the target string and automatically adds ^ to the beginning of the pattern.

D (PCRE_DOLLAR_ENDONLY) If this modifier is set, the dollar metacharacter in the pattern matches only the end of the target string. Without this option, if the last 1 character is a newline character, the dollar sign will also match before this character (but not before any other newline characters). If the m modifier is set, this option is ignored. There is no equivalent modifier in Perl. S When a pattern is to be used several times, it is worth analyzing first in order to speed up matching. If this modifier is set, additional analysis will be performed. Currently, parsing 1 pattern is only useful for non-anchored patterns without a single 1 fixed start character.

U (PCRE_UNGREEDY) This modifier reverses the value of the number of matches so that it is not the default duplicate, but follows the "?" It becomes repetitive. This is not compatible with Perl. You can also set (? U) to enable this option.

X (PCRE_EXTRA) This modifier enables one additional feature in PCRE that is not compatible with Perl. Any backslash in the pattern followed by a letter with no special meaning causes an error, thus preserving the combination for future expansion. By default, like Perl 1, a backslash followed by a letter with no special meaning is regarded as the letter itself. No other attributes are currently controlled by this modifier. That is, greedy mode, which matches such as:/a [\ w] +? e/U matches abceade in abceadeddd instead of abce, and matches abce u without U correction (PCRE_UTF8) This correction enables an additional feature in PCRE that is not compatible with Perl. The pattern string is treated as UTF-8. This correction is available under Unix from PHP 4.1. 0 and under win 32 from PHP 4.2. 3.


Related articles: