PHP Regular expression pattern modifiers

Source: Internet
Author: User
Tags modifiers php regular expression

The PHP pattern modifier, also known as the pattern modifiers, is used outside the delimiter of the regular expression. Mainly used to adjust the interpretation of regular expressions, to extend the regular expression in the matching, substitution and other operations of some functions, enhance the ability of the regular. But there are a lot of local explanations are wrong, it is easy to mislead others, so today I put this document out for your reference.

tr>
mode modifier symbol function Description
i in and regular match is case insensitive
m treats a string as multiple lines. The default regular start "^" and End "$" Use the target note string as a single "line" character (even including newline characters). If you add "M" to the modifier, the start and end of each line that will be pointing to the string begins with "^" Ending and "$".
s If this modifier is set, the matched string will be treated as a line, including a newline character, and the newline character will be treated as a normal string.
x ignores whitespace unless escaped is not ignored.
e is used only in the Preg_replace () function, where the inverse reference in the replacement string is a normal substitution, which (that is, the "replacement string") is evaluated as a PHP code and replaced by the result of the search The string.
A If you use this modifier, the expression must be the beginning of the matching string. For example, "/a/a" matches "ABCD". The $ character Fu Quan in
D mode matches the end of the target character. Without this option, if the last character is a line break, the dollar sign will also match this character. If modifier m is set, this is ignored.
E and "M" instead, if you use this modifier, "$" will match the end of the absolute string instead of the newline character, which is turned on by default.
U greedy mode, similar to the role of the question mark, the maximum match is greedy mode.

PHP Regular expression pattern modifiers detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.