PHP Regular:

Source: Internet
Author: User

Regular is used to handle strings in a text pattern that can match, find, replace, and split strings. Regular is composed of atoms (ordinary strings), some special meanings of characters, and delimiters, pattern modifiers.

The delimiter indicates that the regular expression has been written and is generally used/to represent.

Atoms are arbitrary characters, and different characters that are special to the regular need to be escaped before they can be used, such as. + * ?

Some provisions of the simplified special characters: \d matches any number, \d out numeric characters, \w numbers and letters, underscores \w \s any white space character

Yenzi:

* 0 times, one or more times

+ one or more times

? 0 or one time.

. Any character other than line breaks

| branch Selection

{N},{n,m}

^ or \a match start

$ or \z match end

\b Match word boundaries

\b does not match word boundaries

[]

[^]

()

Example:

Match this is test

Boundary limit:

/^this/matches the string at the beginning of this

/test$/match string at end of test

/\bis\b/matches the is character that has boundaries around it, only is matches

/\bis\b/matches a character with a border to the right with only this

Mode modifier:

I is case insensitive

M treats a string as multiple lines

s if set,. matches any character including line breaks

white space negative in x mode

U reverses the value of the matched quantity so that it is not the default repetition, unless it is repeated, or you can add one after the quantifier to make it non-repeating, such as. *?,{n}?, this modifier may be unique to PHP.

Example: if matching ABCDEFGABCDEFGABCDE

/a.*e/will match the entire string,/a.*?e/and/a.*e/u will match ABCDE,

/web server/x will be negative and can match webserver.

/^is/m matches the is test in This\nis test

Common matching rules:

Email

/\w+ ([-+.] \w) *@\w+ ([-.] \w) *\.\w+ ([-.] \w) */

Url:/^http[s]?:\ /\/([\w-]+\.) +[\w-]+ ([\w-./?%&=]*)? $/

English:/^[\u4e00-\u9fa5\uf900-\ufa2d]+$/

ASCII string: ^[\x00-\xff]+$

ip:/(25[0-5]|2[0-4]\d|1\d{2}|[ 1-9]?\d) \.25[0-5]|2[0-4]\d|1\d{2}| [1-9]?\d\.25[0-5]|2[0-4]\d|1\d{2}| [1-9]?\d\.25[0-5]|2[0-4]\d|1\d{2}| [1-9]?\d] */

PHP Regular:

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.