PHP Regular expression Observation points

Source: Internet
Author: User
Tags php regular expression

the function of a regular expression separates, finds, matches, replaces the component separators of a string regular expression"/", "#", "~"General Atomic \d: 0-9 in decimal\d: Reverse \d: Except for 0-9\w:numbers, letters, bottom line \w:In addition to numbers, letters, line \s:spaces, line feeds, page breaks, carriage returns, character \s:Common Atomic characters in addition to spaces, line breaks, page breaks, carriage returns, and word-list characters. :any character other than a line break* :match the preceding content 0, 1, or more times? :Match Previous content 0 or 1 times^ :Opening dollar characters:End+ :match preceding content appears 1 or more times {n}:occurs n times {n,}: appears greater than or equal to n times {n, m}:occurs greater than or equal to n times less than or equal to M times []:Matches the [ABC] in the brackets to match A or B or C ():A back reference or as a whole [^]: take reverse [^ABC] except A, B, except C| :or [-] :represents the range pattern modifier i:Case insensitive m:Multi-text mode s:single-line mode U:Cancel greedy mode x:White space character A in the Ignore pattern:must start with this pattern D: If this modifier is set, the meta-character dollar sign in the pattern matches only the end of the target string. If this modifier is not set, when the string ends with a newline character, the dollar sign also matches the newline character (but does not match any previous newline character). If the modifier m is set,this modifier is ignored u: For utf-8 matching back reference$str= ' <b>abc</b> ';$pattern= '/<b> (. *) <\/b>/';Preg_replace($pattern, ' \\1 ',$str);//What \1 here represents is the match in parentheses, which is ABC .Greedy mode$str= ' <b>abc</b><b>bcd</b> ';//match every non-B tag$pattern= '/<b> (. *?) <\/b>/';//. * There is greedy mode, will always match to the last, with the question mark after the elimination of greedy mode, match one after the next matchPreg_replace($pattern, ' \\1 ',$str);//You can also cancel greedy mode by using the following methods$pattern= '/<b> (. *) <\/b>/u 'The regular expression Pcre function preg_filter-performs a regular expression search and replacePreg_grep-Returns an array entry for the matching pattern preg_last_error-returns the error code resulting from the last pcre regular executionPreg_match_all-Performs a global regular expression matchPreg_match-Perform a matching regular expressionPreg_quote-escaped regular expression character preg_replace_callback_array-perform a regular expression search and replace using callbacksPreg_replace_callback-Performs a regular expression search and replaces it with a callbackPreg_replace-Perform a search and replace of a regular expressionPreg_split-Write a regular expression by separating the string example with a regular expression to remove the SRC value from all the IMG tags in the page$str= '  ";$pattern= '//';/** * Analysis * img tag features: With  or >:/?> * Final stitching:  **/

PHP Regular expression Observation points

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.