Regular expression learning

xiaoxiao2021-03-06  19

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 / Mismatch / "A, / /" in 'A', but matches the most in front of / "an a. /".

Character $ Significance: Similar to ^, match the last character. For example: / T $ / does not match / "Eater /" in 't', but match / "EAT /" 'T'.

Character * Significance: Match * The character is 0 times or N times. For example: / bo * / match / "a ghost boooed /" 'b' in 'b' in 'b', but does not match any 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 / "Candy /" in 'a' in 'A' in "CaaaaaAAndy./".

Character? Significance: Match? The character is 0 times or 1 time. For example: / e? Le? / Match / "Angel /" 'el' and /"angle./ "in 'Le' in" Angel / ".

Character. Significance: (decis) matches all single characters except the linefinder. For example: /. 'An' and 'on' in NAY, 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./" '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 / Match / "Green 'in Green Apple /" RED' in 'Red' in "Red Apple./".

Character {n} meaning: The N here is a positive integer. Match the N characters in front. For example: / a {2} / do not match / "Candy, /" in 'a', but matching / "Caandy, /" in all 'a' A AAAAandy./ "in front of" A " '.

Character {n,} Significance: The N is a positive integer. Match at least n front characters. For example: / a {2,} does not match / "Candy /" in 'A', but matches all 'A' and / "caaaaaaAndy./ "in CAANDY /" All 'A'

Character {n, m} Significance: N and m here are positive integers. Match at least n up to M phed characters. For example: / a {1, 3} / do not match any characters in / "cndy /", but match / "caandy, /" caandy, / "in the" Candy, / "in the two 'A' And / "CaaaaaaAndy /" in front of the three 'a', note: There are many 'A' in / "caaaaaaAndy /", 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 the '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 earlier in the 'h' in 'r' and / "chop./ "in BRISKET /".

Character Significance: Match a space (don't confuse with B)

Character B Significance: Match a word line line, such as a space (do not confused), for example: / bnw / match / "noonday /" 'NO', / WYB / Match / "Possibly YesterDay./" ' LY '.

Character B Significance: Match a non-bound line, for example: / WBN / Match / "Noonday /" 'Ye' in "Possibly YesterDay./".

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 / "B2 is the suite number./" '2'.

Character D Significance: Match any non-figures, equivalent to [^ 0-9]. For example: / D / or / [^ 0-9] / Match / "B2 is the suite number./" 'b'.

Character F Significance: Match a form

Character n Significance: Match a newline

Character R Signature: Match a Enterprise

Character s Significance: Match a single White space character, including space, Tab, Form feed, wrap, equivalent [FNRTV]. For example: / sw * / match / "foo bar./" 'Bar'.

Character s Significance: Match a single character other than WHITE spaces, equivalent to [^ Fnrtv]. For example: / s / w * Match / "foo bar./" 'foo' in "foo bar./".

Character T Signment: Match a tab

Character V Significance: Matching a head tab

Character W Significance: Match all numbers and letters and underscores, equivalent to [A-ZA-Z0-9_]. For example: '3' in '3' in 'A', / "in 'A', /" in "Apple, /" in 'A', / "in" 3 ".

Character W Significance: Match other characters except numbers, letters and underscore, equivalent to [^ A-ZA-ZA-Z0-9_]. For example: / or / 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 SoRange1 / Match / "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 / Tags the next character as a special character, or a primary character, or a backward reference, or an octave. For example, / 'n /' match characters / "n /". / '/ n /' matches a newline. Sequence / '///' Match / "//" / "/ (/" Match / "(/". ^ Match the input string start position. If the demiline property of the regexp object is set, ^ also matches / Location after '/ n /' or / '/ r /'. $ Match the end position of the input string. If the multiline property of the regexp object is set, $ also match / '/ n /' or / '/ r /' Previous position. * Match the previous sub-expression zero or multiple times. For example, ZO * can match / "z /" and / "zoo /". * Equivalent to {0,}. Match the previous child expression One or more times. For example, / 'zo /' can match / "zo /" and / "zoo /", but cannot match / "z/". equivalent {1,}.? Match the previous child The expression is zero or once. For example, / "Do (es) can match /" do / "in /" do / "in" do / ".? Isometric {0,1}. { N} n is a non-negative integer. Match the N times. For example, / 'o {2} /' does not match / "BOB /" / ', but can match / "food /" Two o. {N,} n is a non-negative integer. At least n times. For example, / 'o {2,} /' does not match / "BOB /" / ', but can match / All O./'o {1,} / '等 等 价 价 于 于 于 于 于 于 于 于 于 价 价 价 价 价 价 价 于 价 价 价M} m and n are non-negative integers, where n <= m. minimize n times and matched M times. Liu, / "o {1, 3} /" will match / "foooood /" in the top three O./'o (0, 1 }/ 'is equivalent to /' o? / '. Please note that there is no space between the comma and the two numbers.? When the character is tight in any other restriction ( When the matching mode is non-greedy when the matching mode is unrespected. Match the search string as much as possible. For example, for strings / "ooo /", / 'o ? /' Will match single / "o", and / 'o /' will match all / 'o / '. Match / "/ n /" any single character outside. To match any characters including /' / n / ', use the like /'[./n]/' mode. (Pattern ) Match Pattern and get this match. The acquired match can be generated from the generated mA Tches collection, use submatches collection in VBScript, use {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 / "or /" characters (|) to combine one of a pattern. For example, / 'industr (?: Y | iES) is a more simple expression of ratio /' 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 does not match /" Windows 3.1 / "/" Windows / " . 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 do not 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 /', match / "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 range of / '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 cannot match / "ER / 'in" Verb / ". / B matches non-word boundary.

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

New Post(0)