Home > Backend Development > PHP Tutorial > Special characters in PHP regular expressions_PHP tutorial

Special characters in PHP regular expressions_PHP tutorial

WBOY
Release: 2016-07-15 13:26:02
Original
859 people have browsed it

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, that is, /b/, the character becomes a special character, indicating the dividing line of matching a word.
or:
For several characters, it is usually stated that they are 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. 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 matches the 't' in "eat".

Character*
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 any characters in "Agoat g
runted".

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

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

characters.
Meaning: (decimal point) matches all single characters except line breaks.
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, or by the properties, ..., 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 the 'a's in "caandy," and the first two 'a's in "caaandy.".

Characters { n, } Meaning: n here is a positive integer. Matches at least n previous characters.
For example: /a{ 2, } does not match the 'a' in "candy", but matches all the 'a's in "caandy" and all the 'a's 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 character in "cndy", but matches the 'a' in "candy," and the first two
'a' in "caandy," And the first three 'a's in "caaaaaaandy", note: even if there are many 'a's in "caaaaaaandy", only the first three 'a's, that is, "aaa" are matched.

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: One-character complement, that is, it matches everything except the listed characters. You can use hyphens to indicate a range of characters.
For example: [^abc] and [^a-c] are equivalent, they first match the 'r' in "brisket" and the 'h' in "chop.".

Characters
Meaning: Match a space (not to be confused with b)

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

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

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

Character d Meaning: Matches 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 the 'B' in "B2 is the suite number."

Character f Meaning: Match a form character

Character n Meaning: Match a newline character


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446640.htmlTechArticleCharacter/ 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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template