Home  >  Article  >  Backend Development  >  Regular expression system tutorial (5)_PHP tutorial

Regular expression system tutorial (5)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:20:47983browse

5. All symbol explanations

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532537.htmlTechArticle5. All symbol interpretation character description marks the next character as a special character, or a literal character, or A backreference, or an octal escape character. For example, n matches the word...
Character Description
Marks the next character as a special character, or a literal character, or a backreference, or an octal escape character. For example, n matches the character "n". Matches a newline character. The sequence matches "" and "(" matches "(".
^ Matches the beginning of the input string. ^ also matches if the RegExp object's Multiline property is set or the position after.
$ Matches the end position of the input string. $ also matches if the RegExp object's Multiline property is set or previous position.
* Matches the preceding subexpression zero or more times. For example, zo* matches "z" and "zoo". * Equivalent to {0,}.
+ Matches the preceding subexpression one or more times. For example, zo+ matches "zo" and "zoo", but not "z". + is equivalent to {1,}.
? Matches the preceding subexpression zero or one time. For example, "do(es)?" would match "do" or "do" in "does". ? Equivalent to {0,1}.
{n} n is a non-negative integer. Match a certain number of n times. For example, o{2} does not match the o in "Bob", but it does match both o's in "food".
{n,} n is a non-negative integer. Match at least n times. For example, o{2,} does not match the o's in "Bob", but it matches all o's in "foooood". o{1,} is equivalent to o+. o{0,} is equivalent to o*.
{n,m} M and n are both non-negative integers, where n
? The matching pattern is non-greedy when the character immediately follows any of the other qualifiers (*, +, ?, {n}, {n,}, {n,m}). Non-greedy mode matches as little of the searched string as possible, while the default greedy mode matches as much of the searched string as possible. For example, for the string "oooo", o+? will match a single "o", while o+ will match all o's.
. Match except " " Any single character other than ". To match include Any characters, please use something like [. ] mode.
(pattern) Match pattern and get this match. The matches obtained can be obtained from the generated Matches collection, using the SubMatches collection in VBScript or the $0…$9 properties in JScript. To match parentheses characters, use ( or ).
(?:pattern) Matches the pattern but does not get the matching result, which means that this is a non-getting match and is not stored for later use. This is useful when using the "or" character (|) to combine parts of a pattern. For example, industr(?:y|ies) is a shorter expression than industry|industries.
(?=pattern) Forward lookup, matches the search string at the beginning of any string matching pattern. This is a non-fetch match, that is, the match does not need to be fetched for later use. For example, Windows (?=95|98|NT|2000) matches "Windows" in "Windows 2000" but not "Windows" in "Windows 3.1". Prefetching does not consume characters, that is, after a match occurs, the search for the next match begins immediately after the last match, rather than starting after the character containing the prefetch.
(?!pattern) Negative lookahead, matches the search string at the beginning of any string that does not match pattern. This is a non-fetch match, that is, the match does not need to be fetched for later use. For example, Windows (?!95|98|NT|2000) matches "Windows" in "Windows 3.1", but not "Windows" in "Windows 2000".Prefetching does not consume characters, that is, after a match occurs, the search for the next match starts immediately after the last match, rather than starting after the characters containing the prefetch
x|y Match x or y. For example, z|food matches "z" or "food". (z|f)ood matches "zood" or "food".
[xyz] Character collection. Matches any one of the characters contained. For example, [abc] matches the a in "plain".
[^xyz] A collection of negative value characters. Matches any character not included. For example, [^abc] matches the p in "plain".
[a-z] Character range. Matches any character within the specified range. For example, [a-z] matches any lowercase alphabetic character in the range a through z.
[^a-z] Negative character range. Matches any character not within the specified range. For example, [^a-z] matches any character that is not in the range a through z.
Matches a word boundary, which refers to the position between a word and a space. For example, er can match er in "never" but not in "verb".
B Matches non-word boundaries. erB matches the er in "verb", but not the er in "never".
cx Matches the control character specified by x. For example, cM matches a Control-M or carriage return character. The value of x must be one of A-Z or a-z. Otherwise, c is treated as a literal c character.
d Matches a numeric character. Equivalent to [0-9].
D Matches a non-numeric character. Equivalent to [^0-9].
f matches a form feed. Equivalent to x0c and cL.
matches a newline character. Equivalent to x0a and cJ.
matches a carriage return character. Equivalent to x0d and cM.
s Matches any whitespace character, including spaces, tabs, form feeds, etc. Equivalent to [ f v].
S matches any non-whitespace character. Equivalent to [^ f v].
matches a tab character. Equivalent to x09 and cI.
v Matches a vertical tab character. Equivalent to x0b and cK.
w Matches any word character including an underscore. Equivalent to [A-Za-z0-9_].
W Matches any non-word character. Equivalent to [^A-Za-z0-9_].
xn Match n, where n is the hexadecimal escape value. The hexadecimal escape value must be exactly two digits long. For example, x41 matches "A". x041 is equivalent to x04 & "1". ASCII encoding can be used in regular expressions. .
um
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