Special characters in regular expressions

zhaozj2021-02-16  36

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 explaining. For example: / b / match character 'b', by adding a backslash in front of B, that is, / b /, then the character turns into a special character, indicating the boundary of the matching 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 literal. 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 matching character must be at 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 any of the characters in "Agoat G Runted". Character Significance: Match the character in front of the number once 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: (decis) matches all single characters except the linefinder. 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 logs the matching value. For example: / (foo) / match and record "Foo Bar." In 'foo'. Matching substrings can be returned from the results of the result array [1], ..., [n], or by 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} meaning: 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 is a positive integer. Match at least n front characters. For example: / a {2,} does not match 'a' in "Candy", but matches all 'A' characters in "Caandy" all 'A' characters {n, m} meaning: here N and M are all positive 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 listed characters. 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 (do not confuse with B) Character B Significance: Match a word line, such as a space (do not confuse), for example: / bnw / match 'NO', / WYB / Match in "Noonday" 'ly' in "POSSIBLY YesterDay.". Character B Significance: Match a non-bound line of a word, for example: / WBN / Match 'on', / ybw / match "Possibly Yesterday." In "Possibly YesterDay." In "Noonday". 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 table single character n meaning: Match a wrap character R meaning: Match a ridicule character s significant: match a single White space character, including space, Tab, Form feed, newline, 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 Size: Match a tabby character v meaning: match 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, letters and underscore, equivalent to [^ A-ZA-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: OOctal here is an octa-based Escape value, and Xhex is a hexadecimal ESCAPE value that allows embedding ASCII code in a regular expression: The following table is a metamorphic character and its in regular expression. A complete list of behaviors in the context: Character Description / Label as a special character, or a primary character, or a backward reference, or an octatifact. For example, 'n' matches characters "n". '/ n' matches a newline. Sequence '/' matching "/" / ("match" (". ^ Matches the start position of the input string. If the multiline property of the regexp object is set, ^ also matches '/ n' or '/ r' after The location. $ Matches the end position of the input string. If the demiline property of the regexp object is set, $ 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 more. For example, 'ZO "can match" ZO "and" ZOO ", But you can't match "Z". Equivalent to {1,}. • Match the previous child expression zero or once. For example, "Do (es)" can match "do" or "does" "Do ".? Is equivalent to {0,1}. {N} n is a non-negative integer. Match the N times. For example, 'o {2}' does not match 'O' in" Bob ", but can match Two o in "Food" is a non-negative integer. At least n times. For example, 'o {2,}' does not match 'O' in "Bob", but can match "foooO)" "All O.'o {1,} 'is equivalent to' o '.' O {0,} 'is equivalent to' o * '. {N, m} M and N are non-negative integers, Where n <= m. Minimize n times and matched M times. Liu, "O {1, 3}" will match the top three O.'o {0, 1} 'in "foooood" o? '. Please note that there is no space between commas and two numbers.? When this character is tight in any other restriction (*, ,?, {n}, {n,}, {n, m }) The matching mode is unresur a greedy. The default greed mode is as much as possible as possible to match the searched string as possible.

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)' Map "Windows" in Windows 2000, but does not 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) "can match" Windows "in Windows 3.1, but cannot match" Windows "in" Windows 2000 ". It is not consumed by the character, that is, after a match occurs, start the next matching search immediately after the last match, not the X | Y, which matches X or Y after the character containing the queue. 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.

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

New Post(0)