Regular expression grammar details

xiaoxiao2021-03-06  50

Visual Basic Scripting Edition

Regular Expression Syntax

A regular expression is a pattern of text that consists of ordinary characters (for example, letters a through z) and special characters, known as metacharacters. The pattern describes one or more strings to match when searching a body of text. The regular expression serves As a template for matching a character pattern to the string being search.

Here Are Some Examples of Regular Expression You Might Encounter:

Jscriptvbscriptmatches / ^ / s [/ t] * $ / "^ / s * $" match a blank line.//d} }-/d }/d "}" Validate An ID Number Consists OF 2 DIGITS, A HYEN, AND ANOTHER 5 DIGITS.

The Following Table Contains The Complete List of metachacters and their behavior in the context of regular expressions:

CharacterDescription / Marks the next character as either a special character, a literal, a backreference, or an octal escape. For example, 'n' matches the character "n". '/ N' matches a newline character. The sequence '// 'Matches "/" and "/ (" matches "(". ^ matches the position at the beginning of the regexp Object's multiline property is set, ^ also matches the position Following' / n 'or r '. $ Matches the position at the end of the input string. If the RegExp object's Multiline property is set, $ also matches the position preceding' / n 'or' /r'.*Matches the preceding character or subexpression zero or more times , Zo * Matches "Z" and "zoo". * Is equivalent to {0,}. Matches the preceding character times. For example, 'ZO ' matches "zo" and "zoo" , but not "z". is equivalent to {1,}.? Matches the preceding character or subspression zero or one time. For example, "Do (es)?" matches the "do" in "do" or "does "is equivalent to { 0,1} {n} n IS a nonnegative INTEGER. Matches Exactly N Times. For example, 'o {2}' in "bob," but matches the two of "food". { n,} n IS a nonnegative integer. matches at Least N Times. for example, 'o {2,}' does not match the "o" in "bob" and matches all the o's in "fooood". 'o {1 } 'is equivalent to' o '.' o {0,} 'is equivalent to' o * '. {n, m} m and n Are Nonnegative Integers, where n <=

m. Matches at Least N And at Most M Times. for Example, "O {1,3}" Matches The First Three o's in "fooooood". 'o {0,1}' is equivalent to 'o? Note That You Cannot Put a Space Between The Comma and The Numbers.?when this Character Immedierately Follows Any of The Other Quantifiers (*, ,?, {n}, {n,}, {n, m}), The matching pattern is non-greedy. A non-greedy pattern matches as little of the searched string as possible, whereas the default greedy pattern matches as much of the searched string as possible. For example, in the string "oooo", 'o ?' matches A SINGLE "O", while 'o ' matches all 'o's..matches any single character except "/ n". to match any character incruding the' / n ', use a pattern such as' [/ s / s]' . (pattern) Matches pattern and captures the match. The captured match can be retrieved from the resulting Matches collection, using the SubMatches collection in VBScript or the $ 0 ... $ 9 properties in JScript. To match parentheses characters (), use '/ (' Or '/)'.(?:pattern) Matches Pattern But Does NOT CAPTURE THE MATCH, THAT IS, IT IS A NON-CAPTURING MATCH THAT IS NOT Stored for Possible Later Use. this is useful for combining parts of a pattern with the "or" character (|). for esample, 'Industr ( ?: y | ies) is a more economical expression than 'industry | industries' (= pattern) Positive lookahead matches the search string at any point where a string matching pattern begins This is a non-capturing match, that is,.?. THE MATCH IS NOT CAPTURED for POSIBLE LATER USE. for example 'Windows (? = 95 | 98 | NT | 2000)' Matches "Windows" in "Windows 2000" But Not "

Windows "in" Windows 3.1 ". Lookaheads do not consume characters, that is, after a match occurs, the search for the next match begins immediately following the last match, not after the characters that comprised the lookahead. (?! pattern) Negative lookahead matches the search string at any point where a string not matching pattern begins This is a non-capturing match, that is, the match is not captured for possible later use for example 'Windows (95 |..?! 98 | NT | 2000) 'matches "Windows" in "Windows 3.1" but does not match "Windows" in "Windows 2000". lookaheads do not consume characters, that is, after a match occurs, the search for the next match begins immediately following the last Match, Not After the Characters That Comprised The LookaHead.x | Ymatches Either X Or Y. for Example, 'Z | Food' Matches "Z" or "Food". '(z | f) ood' matches "Zood" OR " ". [xyz] a character set. matches any one of the enclosed character, '[abc]' matches the 'a' in" plain ". [^ xyz] a Negative Character S Et. Matches Any Character NOT Enclosed. for Example, '[^ Abc]' matches the 'p' in "plain". [AZ] a Range of Characters. matches any character in the specified range. for example, '[AZ] 'matches any lowercase alphabetic character in the range' a 'through' z '. [^ az] A negative range characters. Matches any character not in the specified range. For example,' [^ az] 'matches any character not in the Range 'A' Through 'Z'. / Bmatches a Word Boundary, That IS, The Position Between A Word and a Space. for Example, 'ER / B' Matches The 'Er'

IN "never" but not the 'er' in "verb". / bmatches a nonword boundary. 'ER / b' matches the 'Er' in "verb" but not the 'Er' in "never". / cxmatches the control CHARACTER INDICATED BY X. for Example, / CM Matches A Control-M or Carriage Return Character. The value of x. if NOT OF AZ or AZ. IF NOTERAL 'C' CHARACTER. / Dmatches a Digit Character. Equivalent TO [0-9]. / DMATCHES A Nondigit Character. Equivalent TO [^ 0-9]. / Fmatches a form-feed character. Equivalent to / x0c and /cl ./nmatches a newline character. Equivalent to / x0a and /cj./rmatches a carriage return character to / x0d and /cm./smatches Any Whitespace Character Including Space, Tab, Form-Feed, etc. Equivalent TO [/ F / N / R / T /V]./smatches any non-white space character character. Equivalent to [^ / f / n / r / t / v]. / TMATCHES A TAB Character. Equivalent to / x09 and /ci./vmatches a Vertical Tab Character. Equivalent to / x0b and / /ck./wmatches Any Word Character Including Underscore. Equivalent to '[A-ZA- Z0-9_] '. / wmatches Any Nonword Character. Equivalent to' [^ a-ZA-Z0-9_] '. / xnmatches n, where n is a hexadecimal escape value. Hexadecimal Escape Valuees Must Be Exactly Two Digits Long. Example, '/ x41' matches "a". '/ x041' IS Equivalent to '/ x04' & "1". Allows ASCII Codes to be used in Regular Expressions./nummatches Num, WHERE NUM IS A POSITITEGER. A Reference Back to captured matches. for example, '(.) / 1'

matches two consecutive identical characters. / nIdentifies either an octal escape value or a backreference. If / n is preceded by at least n captured subexpressions, n is a backreference. Otherwise, n is an octal escape value if n is an octal digit (0 -7) ./ nmIdentifies either an octal escape value or a backreference. If / nm is preceded by at least nm captured subexpressions, nm is a backreference. If / nm is preceded by at least n captures, n is a backreference followed by literal m. if neither of the preceding conditions exists, / nm matches octal escape value nm when n and m it octal Digits (0-7) ./ NMLMATCHES Octal Escape Value Nml when N Is An Octal Digit (0-3) and M and M AND l Are Octal Digits (0-7) ./ Unmatches N, WHERE N IS A Unicode Character Expressed As Four Hexadecimal Digits. for Example, / U00A9 Matches The Copyright Symbol (©) .send Feedback On this Topic to Microsoft

© Microsoft Corporation. All Rights Reserved.

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

New Post(0)