Regular Expression Pattern Modifier

Source: Internet
Author: User

Pattern correction symbols are used outside the regular expression delimiters (after the last slash "/"), for example, "PHP/I ". "/PHP/" is a regular expression pattern, and "I" is the corrected symbol used to correct this pattern, which is case insensitive for matching. The pattern modifier can adjust the interpretation of a regular expression, extend some functions of a regular expression in operations such as matching and replacement, and can also be used in combination with pattern correction symbols, enhanced the processing capability of regular expressions. For example, "/PHP/UIS" is combined with "u", "I", and "S" pattern modifiers. The pattern modifier is helpful for writing concise and simple expressions. The following table lists some common pattern modifiers and their function descriptions, as shown in the following table.

The following are a few simple examples to illustrate the use of the schema modifier in the table. When the mode modifier is used, spaces and line breaks are ignored. If other non-mode correction characters are used, errors may occur. The pattern "/Web server/IX" can be used to match the string "webserver", ignoring case sensitivity and white space. The pattern "/a. * E/" matches the string "abcdefgabcdefgabcdefg". Because ". *" in the pattern matches by greedy, the string matches "abcdefgabcdefgabcde ". From the first "A" Letter to the last "E" letter, it all belongs to the ". *" content, so it is not "ABCDE ". If you want to cancel this greedy match, you want to finish the match from the first letter "a" to the first letter "E" and match the string "ABCDE ", you can use the pattern correction symbol "U" or ". * "followed by"? ", For example, the usage mode is "/a. * E/u" or "/.*? E /". Conversely, if the two are used together and greedy match is enabled, for example, the mode "/.*? E/u matches "abcdefgabcdefgabcde" in the string "abcdefgabcdefgabcdefg" instead of "ABCDE ". We recommend that you use ". *" followed by "?" In the mode. Replace the pattern correction symbol "u", because in some other programming languages, if Perl-Compatible Regular functions are used, there may be no pattern correction symbol "U ", for example, this pattern correction symbol does not exist in JavaScript. The pattern "/^ is/M" can match the is in the string "This \ NIS \ Na \ ntes", because the pattern modifier "M" is used to treat the string as multiple rows, if "is" appears at the beginning of the second line, the match is successful. The default regular start "^" and end "$" treat the target string as a single "line" (or even include line breaks ).

> Fixed link: http://php.ncong.com/php_course/php_zend/xiuzhengfu.html

> For Reprinted Information, please note: ncong PHP was published in ncong PHP learning tutorial on September 10, August 01, 2014.

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.