PHP regular expression topic

xiaoxiao2021-03-06  15

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 'b' in 'boooo' in "a ghost boooed", but does not match "Agoat 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'.

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 by the properties of the regexp object, ..., return.

Character x│y

Significance: Match 'x' or 'Y'.

For example: / Green│RED / The 'Red' in 'Green' in "Green Apple" is matched.

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

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 'A' "AAA" in front.

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 hyphen - pointing out a range of characters.

For example: [^ ABC] and [^ a-C] equivalence, they first match 'h' in 'r' and "chop." In "BRISKET".

character

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)

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', ". 28," in "Apple," in '3' in '3'.

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, orange 'in the "Apple, Orange, Cherry, Peach." There is a more complete example below.

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: The OOctal here is an octa ESCAPE value, and Xhex is a hexadecimal ESCAPE value that allows an ASCII code to be embedded in a regular expression.

Attachment: The following table is a complete list of metammatics and its behavior in the regular expression context:

Character description

/ Tag the next character as a special character, or a primary character, or a backward reference, or an octave. For example, 'n' matches characters "n". '/ n' matches a newline. Sequence '' matching "/" "/ (" matches "(".

^ Match the start position of the input string. If the multiline property of the regexp object is set, ^ also matches the location after '/ n' or '/ r'.

$ Match the end position of the input string. If the multiline property of the Regexp object is set, the $ also matches the position before '/ n' or '/ r'.

* Match the previous sub-expression zero or multiple times. For example, ZO * can match "Z" and "ZOO". * Equivalent to {0,}.

Match the previous sub-expression once or multiple times. For example, 'ZO ' can match "ZO" and "ZOO" but cannot match "Z". Equivalent to {1,}.

• Match the previous sub-expression zero or once. For example, "Do (ES)" can match "do" in "do" or "does". Is equivalent to {0,1}.

{n} n is a non-negative integer. Match the determined N times. For example, 'o {2}' does not match 'o' in "Bob", but can match two O in "Food".

{n,} n is a non-negative integer. At least n times. For example, 'o {2,}' cannot match 'O' in "Bob", but can match all O in "fooOOD". 'o {1,}' is equivalent to 'o '. 'o {0,}' is equivalent to 'o *'.

{N, M} M and N are non-negative integers, where n <= m. Match at least n times and matched M times. Liu, "O {1, 3}" will match the top three O in "foooood". 'o {0,1}' is equivalent to 'o?'. Please note that there is no space between commas and two numbers.

• The matching mode is non-greed when the character is tightly followed by any other restriction (*, , {n}, {n,}, {n, m}). Non-greedy patterns match the search for strings as little as possible, and the default greed mode is as many as possible to match the search string. For example, for the string "OOOO", 'o ?' Will match a single "O", and 'o ' will match all 'o'. Match any individual characters other than "/ n". To match any characters including '/ n', use the mode of '[./n]'.

(Pattern) Match Pattern and get this match. The acquired match can be obtained from the generated Matches, using the Submatches collection in VBScript, using {content} ... attributes in JScript. To match the bracket characters, use '/ (' or '/)'.

(?: pattern) Match Pattern but does not acquire the matching result, that is, this is a non-acquired match, not to use it after storage. This is useful to use the "or" character (│) to combine a pattern. For example, 'Industr (?: Y│ies) is a smale of' Industry│industries'.

(? = pattern) Positive to check, match the lookup string at any string of Pattern. This is a non-acquisition match, that is, the match does not need to be used later. For example, 'Windows (? = 95│98│NT│2000 "can match" Windows "in" Windows 2000 ", but cannot match" Windows "in" Windows 3.1 ". It is not consumed by the character, that is, after a match occurs, start the next matching search immediately after the last match, not starting from the character containing the pre-check.

(?! pattern) negotiation, match the lookup string at any string of any mismatch at any Point WHERE A STRING NOT MATCHING POINT WHERE A STRING NOT MATCHING PATTERN. This is a non-acquisition match, that is, the match does not need to be used later. For example, 'Windows (?! 95│98│nt│2000) Match "Windows" in "Windows 3.1", but does not match "Windows" in "Windows 2000". The forecast does not consume characters, that is, after a match occurs, start the next matching search immediately after the last match, instead of starting from the character included in the queue

X│Y matches X or Y. For example, 'z│FOOD' can match "Z" or "Food". '(z│F) OOD' matches "Zood" or "Food".

[XYZ] Character collection. Match any of the included characters. For example, '[abc]' can match 'a' in "Plain".

[^ XYZ] Negative character set. Match any of the characters that are not included. For example, '[^ ABC]' can match 'P' in "Plain". [A-Z] character range. Match any of the characters within the specified range. For example, '[a-z]' can match any lowercase alphabetic characters in the 'A' to 'Z' range.

[^ a-z] Negative character range. Match any of any characters that are not within the specified range. For example, '[^ a-z]' can match any of any characters that are not in the 'A' to 'Z'.

/ b Match a word boundary, that is, the location of the words and spaces. For example, 'er / b' can match 'ER' in "Never", but do not match 'Er' in "Verb".

/ B matches non-word boundary. 'ER / B' can match 'Er' in "Verb", but cannot match 'Er' in "Never".

/ CX matches the control character indicated by x. For example, / cm matches a Control-M or an Enterprise. The value of x must be one of A-Z or A-Z. Otherwise, the C is treated as a primary 'c' character.

/ d Match a numeric character. Equivalent to [0-9].

/ D Match a non-digital character. Equivalent to [^ 0-9].

/ f Match a change page. Equivalent to / x0c and / cl.

/ n Match a newline. Equivalent to / x0a and / cj.

/ r Match a carriage return. Equivalent to / X0D and / cm.

/ s Match any blank character, including spaces, tabs, change page, and the like. Equivalent to [/ f / n / r / t / v].

/ S Match any non-blank character. Equivalent to [^ / f / N / R / T / V].

/ t matches a tab. Equivalent to / x09 and / ci.

/ v Match a vertical tab. Equivalent to / x0b and / ck.

/ w Match any word character that includes underscore. Equivalent to '[A-ZA-Z0-9_]'.

/ W Match any non-word characters. Equivalent to '[^ a-za-z0-9_]'.

/ XN matches n, where n is a hexadecimal escape value. The hexadecimal escape value must be a determined two numbers long. For example, '/ x41' matches "a". '/ x041' is equivalent to '/ x04' & "1". ASCII coding can be used in regular expressions. .

/ NUM matches NUM, where NUM is a positive integer. References to the acquired match. For example, '(.)' Matches two consecutive identical characters.

/ n identifies an octal escape value or a rearward reference. If the sub-expression of at least N before / N, n is a backward reference. Otherwise, if n is an octal number (0-7), then n is an eight-input escape value.

/ Nm identifies an octal escape value or a backward reference. If the / nm has at least IS Preceded by Least NM acquired a sub-expression, the nm is a backward reference. If there is at least n acquisitions before / nm, then n is a rear reference reference to the text M. If the previous conditions are not satisfied, if n and m are octal numbers (0-7), the / nm will match the eight-way escape value Nm.

/ Nml If n is an octal number (0-3), and M and L are eight-input numbers (0-7), match the eight-en-en-escaic value NML.

/ UN matches N, where N is a Unicode character represented by four hexadecimal numbers. For example, / u00A9 matches copyright symbol (?).

转载请注明原文地址:https://www.9cbs.com/read-47430.html

New Post(0)