Regular - First entry

Regular

Regular expressions (regular expression) describes a set of strings (pattern), it can be used to check whether a string containing the certain substring, replacing the sub-string matching or removed from a string meet a certain criteria substring and so on.

  • Nlife + a, match Nlifea, the foregoing Nlifeea, Nlifeeea ......, + representing the character number occurs at least once.
  • Nlife * a, can match Nlifa, front Nlifea, Nlifeea, Nlifeeea ......, * represents the number of characters may not appear, or appear more than once.
  • Nlife? A, can match Nlifa, Nlifea ,? representatives appear or not appear.

Qualifier

  • * - Matches the preceding subexpression zero or more times. For example, zo * matches "z" and "zoo". * Is equivalent to {0}.
  • + - Matches the preceding subexpression one or more times. For example, 'zo +' will match "zo" and "zoo", but can not match the "z". + Is equivalent to {1}.
  • ? - Matches the preceding subexpression zero or one. For example, "do (es)?" Matches "do", "does" in the "does", "doxy" in the "do". ? Is equivalent to {0,1}.
  • {N} - n is a non-negative integer. Matching the determined n times. For example, 'o {2}' does not match the "Bob" in the 'o', but can match the "food" in the two o.
  • {N,} - n is a non-negative integer. Matching at least n times. For example, 'o {2,}' does not match the "Bob" in the 'o', but it can match all o "foooood" in. '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 match up to m times. For example, "o {1,3}" will match "fooooood" in the previous three o. 'O {0,1}' is equivalent to 'o?'. Please note that no spaces between the comma and the two numbers.

Locator

  • ^ - matches the input string starting position. If the object is set RegExp Multiline property, ^ also matches the position after the \ n or \ r.
  • $ - matches the input end of the string position. If the object is set RegExp Multiline property, also with $ \ n or \ r position before matching.
  • \ B - matches a word boundary, that is, the position between a word and a space.
  • \ B - Non-word boundary matching.
E.g
Plastic integer multiply
In this way we can canonical match / Multiply ^ [ . 1 - . 9 ] [ 0 - . 9 ] * /
But this has the disadvantage that it will match many rows, if we want to match a single line to how to do it?
Such can / Multiply ^ [ . 1 - . 9 ] [ 0 - . 9 ] * $ /
The word can multiply this match
/ \ bmul / or / ply \ b / 
can / \ Blti /

Special symbols

  • \ Cx - x specified by matching control characters. For example, \ cM matches a Control-M or carriage return. The value of x must be AZ or az. Otherwise, c as a literal 'c' character.
  • \ F - match for a website 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 - to match any whitespace characters, including spaces, tabs, page breaks, and so on. Is equivalent to [\ f \ n \ r \ t \ v]. Note Unicode Regular Expressions will match full-width space character.
  • \ S - Matches any non-whitespace characters. Is equivalent to [^ \ f \ n \ r \ t \ v].
  • \ T - match a tab. Equivalent to \ x09 and \ cI.
  • \ V - matches a vertical tab. Equivalent to \ x0b and \ cK.

Incomplete reprint

Guess you like

Origin www.cnblogs.com/Nlifea/p/11756097.html