A list of special characters in regular expressions _php tutorial

Source: Internet
Author: User
Special characters in regular expressions:

Character
Meaning: For a character, it is usually expressed as literal meaning that the next character is a special character and is not interpreted.
For example:/b/matches the character B, by adding a backslash in front of B, which is/b/, the character becomes a special character, indicating
Match the dividing line of a word.
Or:
For several characters, the usual description is special, which indicates that the characters immediately followed are not special, but should be interpreted literally.
For example: * is a special character that matches any character (including 0 characters); For example:/a*/means matching 0 or more aces.
To match the literal *, precede a with a backslash; For example:/a*/matches a *.

Character ^
Meaning: The character that represents the match must be at the front.
For example:/^a/does not match "an A," in a, but matches "an A." In the top of a.

Character $
Meaning: Similar to ^, matches the last character.
For example:/t$/does not match T in "Eater", but matches T in "eat".

Characters
Meaning: matches the preceding character 0 or n times.
For example:/bo*/matches B in "a Ghost booooed" in Boooo or "a bird warbled", but does not match "a goat g
Any characters in the runted ".

Character +
Meaning: Matches the character preceding the + sign 1 or n times. Equivalent to {1,}.
For example:/a+/matches A and "Caaaaaaandy" in "Candy". All a in the.

Character?
Meaning: match the preceding character 0 or 1 times.
For example:/e?le?/matches el in "Angel" and "angle." In the Le.

Character.
Meaning: (decimal point) matches all the individual characters except the line break.
For example:/.n/matches an and on of "Nay, an apple was on the tree" but does not match nay.


Character (x)
Meaning: Match x and record the matching value.
For example:/(foo)/Match and record "Foo bar." In the Foo. The matched substring can be in the result array of the vegetarian [1], ..., [n] Return
Back, or the property of the RegExp object, $ ..., $9 returns.

Character X|y
Meaning: match x or Y.
For example:/green|red/matches green apple and red apple. In the red.

Character {n}
Meaning: n Here is a positive integer. Matches the preceding n characters.
For example:/a{2}/does not match a in "candy," but matches all a in "Caandy," and "Caaandy." In front of the two
A.

Character {n,}
Meaning: n Here is a positive integer. Matches at least n preceding characters.
For example:/a{2,} does not match a in "Candy", but matches all A and "Caaaaaaandy" in "Caandy". All A In the

Character {n,m}
Meaning: Both N and m are positive integers. Matches at least N of the characters up to M preceding.
For example:/a{1,3}/does not match any of the characters in "Cndy", but matches "candy," in the first two in "A," "Caandy,"
A and "Caaaaaaandy" in front of the three A, note: even if "caaaaaaandy" There are many a, but only match the previous three
A is "AAA".

character [XYZ]
Meaning: A list of characters that matches any one of the characters listed. You can use hyphens-to indicate a range of characters.
For example: [ABCD] is the same as [a-c]. They match C in "brisket" in B and "ache".

character [^XYZ]
Meaning: A character complement, that is, it matches everything except the listed characters. You can use hyphens-to indicate a
The character range.
For example: [^ABC] and [^a-c] are equivalent, they first match R in "brisket" and "chop." In the H.

character [b]
Meaning: Match a space (do not confuse with B)

Character B
Meaning: Match the dividing line of a word, such as a space (not to be confused with [b])
For example:/bnw/matches the no,/wyb/match "possibly yesterday" in "Noonday". In the LY.

Character B
Meaning: Match the non-dividing line of a word
For example:/wbn/matches the on,/ybw/match "possibly yesterday" in "Noonday". In the Ye.

Character CX
Meaning: The x here is a control character. Matches the control character of a string.
For example:/cm/matches a control-m in a string.

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

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

Character F
Meaning: Match a single form character

Character N
Meaning: Match a line break

Character R
Meaning: Match a carriage return character

Character S
Meaning: Match a single white space character, including spaces, tab,form feeds, line breaks, equivalent to [FNRTV].
For example:/sw*/matches "foo bar." Bar in the.

Character S
Meaning: matches a single character except white space, equivalent to [^ FNRTV].
For example:/s/w* matches "foo bar." In the Foo.

Character T
Meaning: Match a tab

Character V
Meaning: Match a head tab

Character W
Meaning: Matches all numbers and letters as well as underscores, equivalent to [a-za-z0-9_].
For example:/w/matches "Apple," in A, "$5.28," in 5 and "3D." In the 3.

Character W
Meaning: Matches other characters except numbers, letters, and underscores, equivalent to [^a-za-z0-9_].
For example:/w/or/[^ $A-za-z0-9_]/match "50%." % in the.

Character N
Meaning: n Here is a positive integer. Matches the value of N of the last substring of a regular expression (counting the left parenthesis).

For example:/apple (,) sorange1/matches "Apple, orange, cherry, peach." In the apple, Orange, below
There is a more complete example.
Note: If the number in the left parenthesis is smaller than the number specified by N, then N takes a line of octal escape as a description.

Characters Ooctal and Xhex
Meaning: The ooctal here is an octal escape value, while Xhex is a hexadecimal escape value that allows the embedding of ASCII code in a regular expression.

http://www.bkjia.com/PHPjc/508417.html www.bkjia.com true http://www.bkjia.com/PHPjc/508417.html techarticle special characters in regular expressions: character meaning: For characters, it usually means literal meaning that the next character is a special character and is not interpreted. Example:/b/match character B, pass ...

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