Regular expression syntax

xiaoxiao2021-03-05  26

Regular expression syntax Published: 2003-11-26 Click: 8243 Regular expression syntax Source: 山 夜 http://www.33d9.com Regular expression syntax A regular expression is made of normal characters (such as characters A to Z) and text mode composed of special characters (called metammatics). This mode describes one or more strings to be matched when the text body is looking for. Regular expression As a template, a character mode matches the search string. Here are some regular expressions that may be encountered: Visual Basic Scripting Edition VBScript Match / ^ / [/ T] * $ / "^ / [/ t] * $" matches a blank line. // D {2} - / d {5} / "/ d {2} - / d {5}" Verify that one ID number is composed of a 2-digit, a hyphen, and a 5-digit. /< (.*)>.*

/ "<(. *)>. *

"Match an HTML tag. The following table is a full list of metamorphic characters and its behavior in the regular expression context: Character Description / Mark the next character as a special character, or a primary character, or a backward reference Or an octal escape. For example, 'n' match characters "n". '/ N' matches a newline. Sequence '//' match "/" / ("match" (". ^ Match Enter the start position of the string. If the multiline property of the regexp object is set, ^ also matches the location after '/ n' or '/ r'. The $ matching the end position of the input string. If you set the multiline property of the regexp object, $ Also matching '/ n' or '/ r' before position. * Match the previous sub-expression zero or multiple times. For example, ZO * can match "Z" and "ZOO". * Equivalent {0, }. Match the previous sub-expression once or more. For example, 'ZO ' can match "ZO" and "ZOO", but cannot match "Z". Equivalent {1,}.? Match the front The expression is zero or once. For example, "do (es)" can match "do" in "do" or "does".? Isometric {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 the two o. {N,} n is a non-negative integer. At least Match n times. For example, 'o {2,}' does not match 'O' in "Bob", but can match all O.'o {1,} 'in "fooOOD" equivalent to' o '.'. ' O {0,} 'is equivalent to' o * '. {n, m} m and n are non-negative integers, where n <= m. Count the N times and matches M times. "o {1, 3} "will match the top three O.'o {0, 1} 'in" foooood "is equivalent to' o? '. Please note that there is no space between comma and two numbers.? When this character is tight When following any other restrictions (*, ,?, {N}, {n,}, {n, m}), the matching mode is non-greedy. Non-greedy mode matches the selected characters as possible String, and the default greed mode matches the search for strings as much as possible. For example, for strings "OOOO", 'o ?' Will match a single "O", and 'o ' will match all 'o'. Match any single character other than "/ n". To match any characters including '/ n', use the pattern of '[./n]'. (PA Ttern) Match Pattern and get this match. The acquired matches can be obtained from the generated Matches, using the Submatches collection in VBScript, using $ 0 ... $ 9 properties in Visual Basic Scripting Edition. 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. 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.

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

New Post(0)