Special characters in regular expressions:
character
Significance: For characters, it is usually represented by literal meaning, indicating that the following characters are special characters, not explained.
For example: / b / match characters 'b', by adding a backslash in front of B, that is, / b /, then the character turns a special character, indicating
Match the boundary line of a word.
or:
For a few characters, it is usually noted that it is special, indicating that the following characters are not special, but should be explained by literally.
For example: * is a special character, matching any means (including 0 characters); for example: / a * / means matches 0 or more A.
In order to match the literal *, a backslash is added in front of a; for example: / a * / match 'a *'.
Character ^
Significance: The character indicating that the match must be in the forefront.
For example: / ^ A / does not match 'A' in "AN A,", but matches the most in front of "AN A.".
Character $
Significance: Similar to ^, match the last character.
For example: / t $ / does not match 'T' in "Eater", but match 't' in "EAT".
character*
Significance: Match * The character is 0 times or N times.
For example: / bo * / Match 'Boooo' or "A Bird Warbled" in "a ghost boooed", but does not match "a Goat G
Any characters in Runted.
Character
Significance: Match the characters in front of the number or N times. Equivalent to {1,}.
For example: / a / match All 'A' in 'A' in "Candy". "All 'A' in" CaaaaAAAandy. ".
character?
Significance: Match? The character is 0 times or 1 time.
For example: / e? Le? / Match 'el' and "Angle." In "Angel".
character.
Significance: (decimal point) matches all single characters except the linefill.
For example: /. N / match 'an' and 'on' in "NAY, An Apple IS on The Tree", but do not match 'NAY'.
Character (x)
Significance: Match 'X' and record the matching value.
For example: / (foo) / match and record "Foo Bar." In 'foo'. Matching substrings can be returned in the array of results [1], ..., [n]
Back, or returned by the property of the regexp object, ..., $ 9.
Character X | Y
Significance: Match 'x' or 'Y'.
For example: / Green | RED / Match 'Red' in 'Green' in "Green Apple".
Character {n}
Significance: The N here is a positive integer. Match the N characters in front.
For example: / a {2} / does not match 'a' in "Candy,", but matches all of 'A' and "Caaandy." In "Caandy,".
'A'.
Character {n,}
Significance: The N here is a positive integer. Match at least n front characters.
For example: / a {2,} does not match 'a' in "Candy", but matches all 'A' and "CaaaaaAAandy in" Caandy "all 'a'.
Character {n, m}
Significance: N and M here are integrated integers. Match at least n up to M phed characters.
For example: / a {1, 3} / does not match any character in "cndy", but matches "Caandy," in "Caandy," in front of "Caandy," in front of "CaaaaaaaAandy" in front Three 'a', pay attention: there are many 'a' in "CaaaaaAndy", but only match the three in front
'A' "AAA".
Character [xyz]
Significance: A list of characters, matching any of the characters listed. You can use even characters - pointing out a range of characters.
For example: [ABCD] is the same as [A-C]. They match 'c' in 'B' and "Ache" in "Brisket".
Character [^ xyz]
Significance: A character is replenished, that is, it matches everything except the list listed. You can use a hobby - pointing out one
Character range.
For example: [^ ABC] and [^ a-C] equivalence, they first match 'h' in 'r' and "chop." In "BRISKET".
Character [b]
Significance: Match a space (don't confuse with B)
Character B
Significance: Match the boundary line of a word, such as a space (don't confuse [B])
For example: / BNW / Match 'NO', / WYB / Match "Possibly YesterDay." In "Noonday".
Character B
Significance: Match a non-bound line of a word
For example: / WBN / Match 'on', / ybw / match "Possibly YesterDay." In "Noonday" 'Ye'.
Character CX
Significance: The x here is a control character. Match a control character of a string.
For example: / cm / matches Control-m in a string.
Character D
Significance: Match a number, equivalent to [0-9].
For example: / d / or / [0-9] / match '2' in "B2 IS the suite number.".
Character D
Significance: Match any non-figures, equivalent to [^ 0-9].
For example: / d / or / [^ 0-9] / match "B2 is the suite number." In 'b'.
Character f
Significance: Match a form
Character N
Significance: Match a newline
Character R
Significance: Match a carriage
Character S
Significance: Match a single White space character, including space, Tab, Form feed, wrap, equivalent [FNRTV].
For example: / sw * / match 'Bar' in "Foo Bar.".
Character S
Significance: Match a single character other than WHITE spaces, equivalent to [^ Fnrtv].
For example: / s / w * Match "Foo Bar." In 'foo'.
Character T
Significance: Match a tab
Character V
Significance: Matching a head tab
Character W
Significance: Match all numbers and letters and underscore, equivalent to [A-ZA-Z0-9_].
For example: / W / Match '3' in 'A', "$ 5.28," in '3' in "Apple," in "Apple,". "
Character W
Significance: Match other characters except numbers, alphabets, and underscore, equivalent to [^ A-ZA-Z0-9_].
For example: / w / or / [^ $ A-ZA-Z0-9 _] / match "50%." In '%'. Character n
Significance: The N here is a positive integer. Match the value of the N of the last substring of a regular expression (count left brackets).
For example: / apple (,) 'apple, orange', below "Apple, Orange, Cherry, Peach."
There is a more complete example.
Note: If the number in the left wrapping brackets is smaller than the number specified, n is removed as a description of the octal ESCAPE.
Character OOCTAL and XHEX
Significance: OOCTAL here is an octaves, and Xhex is a hexadecimal ESCAPE value that allows an ASCII code to be embedded in a regular expression.
(Author: Liao far)
Reprinted:
Www.php2000.com