PHP regular expression special character _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Special characters in PHP regular expressions. Character meaning: for a character, it usually indicates the literal meaning, indicating that the subsequent character is a special character, not interpreted. For example, B matches the character 'B' by adding a backslash before B. Character/
Meaning: for characters, it usually indicates the literal meaning, indicating that the subsequent characters are special characters, not explained.
For example, if/B/matches the character 'B' and adds a backslash (/B/) before B, the character becomes a special character, the line that matches a word.
Or:
For a few characters, it is generally described as special. it is pointed out that the subsequent characters are not special, but should be interpreted literally.
For example, * is a special character that matches any character (including 0 characters). For example,/a */indicates that it matches 0 or multiple a characters. To match the literal *, add a backslash before a. For example,/a */matches 'A *'.

Character ^
Meaning: the matched characters must be at the frontend.
For example,/^ A/does not match 'A' in "an A,", but matches 'A' in the top of "An '.

Character $
Meaning: similar to ^, it matches the last character.
For example,/t $/does not match 't' in "eater", but matches 't' in "eat '.

Character *
Meaning: match the first character of * 0 or n times.
For example,/bo */matches 'boooo' in "A ghost booooed" or 'B' in "A bird warbled", but does not match "Agoat g
Any character in runted.

Character +
Meaning: match the character before the plus sign once or n times. It is equivalent to {1 ,}.
For example,/a +/matches all 'A' in "candy" and "caaaaaaandy '.

Character?
Meaning: match? The first character is 0 or 1 time.
Example:/e? Le? /Match 'El' in "angel" and 'le' in "angle '.

Character.
Meaning: (decimal point) match all single characters except line breaks.
For example,/. n/matches 'any' and 'on' in "nay, an apple is on the tree", but does not match 'nay '.

Character (x)
Meaning: Match 'X' and record the matched value.
For example,/(foo)/matches and records 'foo' in "foo bar '. Matching substrings can be returned by the element [1],..., [n] in the result array.
Return, or be returned by RegExp object attributes.

Character x │ y
Meaning: Match 'X' or 'y '.
For example,/green │ red/matches 'green' in "green apple" and 'red' in "red apple '.

Character {n}
Meaning: Here n is a positive integer. Match the previous n characters.
For example:/a {2}/does not match 'A' in "candy,", but matches all 'A' and "caaandy" in "caandy. "The first two 'A '.

Character {n ,}
Meaning: Here n is a positive integer. Match at least n first characters.
For example,/a {2,} does not match 'A' in "candy", but matches all 'A' in "caandy" and "caaaaaaandy'

Character {n, m}
Meaning: both n and m are positive integers. Match at least n characters at most before m.
For example,/a {}/does not match any character in "cndy", but matches the first two characters in "candy," 'A', "caandy ,"
'A' and "caaaaaaandy" are the first three 'A'. note: even if "caaaaaaandy" has many 'A ', but only match the first three 'A', that is, "aaa ".

Character [xyz]
Meaning: a one-character list that matches any character in the list. You can use a hyphen to indicate a character range.
For example, [abcd] is the same as [a-c. They match 'B' in "brisket" and 'C' in "ache '.

Character [^ xyz]
Meaning: A character complement, that is, it matches everything except the listed characters. You can use a hyphen to indicate the one-character range.
For example, [^ abc] is equivalent to [^ a-c]. they first match 'R' in "brisket" and 'H' in "chop '.

Character
Meaning: match a space (do not confuse with B)

Character B
Meaning: match the boundary of a word, such as a space (not to be confused)
For example,/bnw/matches 'no' in "noonday",/wyb/matches 'ly 'in "possibly yesterday '.

Character B
Meaning: match the non-dividing line of a word
For example,/wBn/matches 'on' in "noonday",/yBw/matches 'Ye 'in "possibly yesterday '.

Character cX
Meaning: X is a control character. Matches the control character of a string.
For example,/cM/matches control-M in a string.

Character d
Meaning: matching a number is equivalent to [0-9].
For example,/d/or/[0-9]/matches '2' in "B2 is the suite number '.

Character D
Meaning: match any non-number, which is equivalent to [^ 0-9].
For example,/D/or/[^ 0-9]/matches 'B' in "B2 is the suite number '.

Character f
Meaning: match a form character

Character n
Meaning: match a linefeed.


Meaning: for characters, it usually indicates the literal meaning, indicating that the subsequent characters are special characters, not explained. For example:/B/match the character 'B', add a backslash before B...

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.