Home  >  Article  >  Backend Development  >  List of special characters in regular expressions_PHP Tutorial

List of special characters in regular expressions_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:34:521024browse

Special characters in regular expressions:

Character
Meaning: For characters, it usually means literal meaning, indicating that the following characters are special characters without explanation.
For example: /b/ matches the character b. By adding a backslash in front of b, which is /b/, the character becomes a special character, which means
Match a word's boundary.
Or:
For several characters, the specification is usually special, indicating that the following characters are not special and should be interpreted literally.
For example: * is a special character, matching any number of characters (including 0 characters); for example: /a*/ means matching 0 or more a's.
To match a literal *, precede a with a backslash; for example: /a*/ matches a*.

Character ^
Meaning: Indicates that the matching character must be at the front.
For example: /^A/ does not match the A in "an A," but matches the first A in "An A.".

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

Characters*
Meaning: Match the character before * 0 or n times.
For example: /bo*/ matches the boooo in "A ghost booooed" or the b in "A bird warbled", but does not match "A goat g
runted".

Character +
Meaning: Match the character before the + sign 1 or n times. Equivalent to {1,}.
For example: /a+/ matches a in "candy" and all a's in "caaaaaaandy."

Character?
Meaning: Match the character before ? 0 or 1 times.
For example: /e?le?/ matches el in "angel" and le in "angle.".

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


Character(x)
Meaning: Match x and record the matching value.
For example: /(foo)/ matches and records foo in "foo bar." The matching substring can be returned by the elements [1], ..., [n] in the result array
Returned, or returned by the properties $1, ..., $9 of the RegExp object.

Character x|y
Meaning: Match x or y.
For example: /green|red/ matches the green in "green apple" and the red in "red apple.".

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

Character {n,}
Meaning: n here is a positive integer. Matches at least n previous characters.
For example: /a{2,} does not match a in "candy", but matches all a in "caandy" and all a in "caaaaaaandy."

Character {n,m}
Meaning: n and m here are both positive integers. Matches at least n and at most m previous characters.
For example: /a{1,3}/ does not match any characters in "cndy", but matches the a in "candy," and the first two
in "caandy," a and the first three a's in "caaaaaaandy", note: even if there are many a's in "caaaaaaandy", only the first three a's are matched
An a is "aaa".

Character[xyz]
Meaning: A list of characters, matching any character in the list. You can specify a range of characters using the hyphen -.
For example: [abcd] is the same as [a-c]. They match the b in "brisket" and the c in "ache".

Character[^xyz]
Meaning: The one-character complement, that is, it matches everything except the listed characters. You can use hyphens - point out one
Character range.
For example: [^abc] and [^a-c] are equivalent. They match the r in "brisket" and the h in "chop." at the earliest.

Character[b]
Meaning: Matches a space (not to be confused with b)

Character b
Meaning: Match a word boundary, such as a space (not to be confused with [b])
For example: /bnw/ matches no in "noonday", /wyb/ matches ly in "possibly yesterday."

Character B
Meaning: Match the non-breaking line of a word
For example: /wBn/ matches on in "noonday", /yBw/ matches ye in "possibly yesterday."

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

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

Character D
Meaning: Matches any non-number, 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: Matches a newline character

Character r
Meaning: Match a carriage return character

Characters
Meaning: Matches a single white space character, including space, tab, form feed, and newline character, equivalent to [fnrtv].
For example: /sw*/ matches bar in "foo bar."

Character S
Meaning: Matches a single character other than white space, equivalent to [^ fnrtv].
For example: /S/w* matches foo in "foo bar."

Character t
Meaning: Match a tab character

Character v
Meaning: Matches a leading tab character

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

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_]/ matches the % in "50%.".

Character n
Meaning: n here is a positive integer. The value of n that matches the last substring of a regular expression (counting left parentheses).

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

Characters ooctal and xhex
Meaning: ooctal here is an octal escape value, and xhex is a hexadecimal escape value, allowing ASCII codes to be embedded in a regular expression.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508417.htmlTechArticleSpecial characters in regular expressions: Character meaning: For characters, it usually means literal meaning, indicating the following character It is a special character and will not be interpreted. For example: /b/ matches the character b, through...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn