Pattern Modifiers - Modifiers for regular expressions_PHP Tutorial

WBOY
Release: 2016-07-13 17:21:29
Original
815 people have browsed it

Pattern Modifiers - Modifiers for regular expressions

The following are the modifications available in the current regular expression. The names in brackets are the internal PCRE names of those modifiers.

i (PCRE_CASELESS)
If this modifier is set, the expression is not case-sensitive.

m (PCRE_MULTILINE)
By default, PCRE considers the target string value to be a single-line string (even if it does contain multiple lines). The line start mark (^) only matches the beginning of the string, and the line end mark ($) only matches the end of the string, or an end line (unless the E modifier is specified). This is the same as in Perl.

If this modifier is set, the line start and line end structures match the current position of any new line in the target string after or before the current position, as well as every start and end. This is equivalent to /m in Perl Modifier. If the target string does not have "n" characters, or there is no ^ or $ in the pattern, this modifier has no effect.

s (PCRE_DOTALL)
If this modifier is set, a "dot" in the pattern will match all characters, including newlines. Without it, newlines will be excluded. This modifier is equivalent to /s in Perl Modifier. An opposite type, such as [^a] will always match a newline character, regardless of the modifier's restrictions.

x (PCRE_EXTENDED)
If this modifier is set, all whitespace clauses in the pattern will be ignored unless an escape character or an internal type of a character is used, and all unescaped characters outside of the character type The characters between the # signs are also ignored. This is equivalent to the /x modifier in Perl, which allows comments to be added to complex patterns. Note that this only applies to data characters. Space characters will not be in the specified order of pattern characters. appears in.

e
If this modifier is set, preg_replace() will perform normal substitutions involving in the replacement value, the same as in PHP code, and then use it to replace the searched string.

Use this modifier only in preg_replace(); other PCRE functions ignore it.

A (PCRE_ANCHORED)
If this modifier is set, the pattern is forced to be anchored, that is, it matches the value to the beginning of the search string. This effect can be achieved through the appropriate pattern structure itself , that's the only way in Perl.

D (PCRE_DOLLAR_ENDONLY)
If this modifier is set, the $ modifier in the pattern will only match the end of the target string. Without this modifier, the $ character will also match the end of the new line (but no longer before a new line). This modifier is ignored if the m modifier is set. There is no equivalent in Perl.

S
If a pattern will be used multiple times, use a longer time to analyze it to improve the speed of matching. If this modifier is used, additional analysis is performed. Currently, the research mode is only used for non-anchors Pattern, does not have a fixed starting character.

U (PCRE_UNGREEDY)
This modifier flips the "greediness" of the amount so that it is not greedy by default, but can be greedy if you follow it with a question mark (?). This is not compatible with Perl. This can also be passed The (?U) modifier inside the pattern gets.

Extension. By default, in Perl, meaningless characters after a backslash are treated as normal literals. There are currently no other control features




http://www.bkjia.com/PHPjc/532482.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532482.htmlTechArticlePattern Modifiers - Modifiers of regular expressions The following are the modifications available in the current regular expression. The name in brackets is the internal PCRE name of those modifiers. i (PCRE_CASELESS) If...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template