A brief talk on the i,m,s,x,e of PHP regular in detail

Source: Internet
Author: User
The following small series for everyone to bring a cliché about PHP in the regular i,m,s,x,e, respectively, what to say. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.

I
If this modifier is set, the characters in the pattern will match the uppercase and lowercase letters.

M
When this modifier is set, line start and line end match the beginning and end of the entire string, respectively, after and before the newline character.

S
If this modifier is set, the dot character (.) in the pattern matches all characters, including the line break. Without this setting, the line break is not included.

X
If this modifier is set, the whitespace characters in the pattern are ignored except for escaping or being completely ignored in the character class, #以及下一个换行符之间的所有字符 outside the escaped character class, including both ends.

E
If this modifier is set, Preg_replace () makes a normal substitution of the inverse reference in the replacement string,

In. + and * are followed by non-greedy matches: *, +, and? Qualifiers are greedy because they match as many words as possible, but only after they are added with one? You can implement a non-greedy or minimal match.

For example:

<?php$string = "On the plane leave Me  Sdfsdf "; $su = Preg_match ("/\<[]*img.*src[]*\=[]*[\ "|\"] (. +?) [\ "|\ ']/", $string, $match); Match src= content Print_r ($match [1]); Output/UPLOADFILE/2009/0921/20090921091612567.JPG$SU = Preg_match ("/\<[]*img.*src[]*\=[]*[\" |\ '] (. +) [\ "|\ ']/", $ String, $match);p rint_r ($match [1]); Output/uploadfile/2009/0921/20090921091612567.jpg ' border= '?>

Example: (? i):

(? i) in PHP meaning internal modifier, I means case insensitive

Other modifiers are x,m,s,u and so on. Is the same as the pattern modifier we used.

The difference is that it is used inside the pattern. Only in the sub-mode where (? i) is located

Such as

CCC (A (? i)) BCD matches CCCABCD and CCCABCD

And a (? i) BC is the same as the ABC plus \i modifier because (? i) acts on the entire pattern

Back to reference

Adding parentheses around a regular expression pattern or part of a pattern causes the related match to be stored in a temporary buffer, and each captured sub-match is stored according to what is encountered in the regular expression pattern from left to right. The buffer number for the storage sub-match starts at 1 and continues numbering up to 99 sub-expressions. Each buffer can be accessed using ' \ n ', where n is a single or two-bit decimal number that identifies a particular buffer.

You can use the non-capturing metacharacters '?: ', '? = ', or '?! ' to ignore the save of the related match.

The above is a brief discussion of the PHP regular in i,m,s,x,e respectively what the details of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.