Regular assertion Detailed

Regular use of assertions

  • Zero-width assertion

    • Matching the width of zero, satisfies certain conditions / assertions.
    • Zero-width assertion is used to find something before something (but does not include the content), or after, that they like \ b, ^, $, as used to specify a location, the location should meet certain conditions ( That is asserted), and therefore they are also called zero-width assertions.
    • Assert should be used to declare a true fact. Regular expression assertion is true only if the match will continue
  • Zero-width assertion and sub-four

    • First assertion (zero width positive lookahead assertion)

      • Expression: (? = Expression)
      • It indicates the position of the preceding expression matching
      • The first assertion is the right step to perform such strings start to match the first one to find ing (that is, an expression first assertion) and then matching its previous expression, if not then continue to find the first match ing two match then the string in front of the second ing, if the matching match
      • . * (? = D) may be abcdefghi c to match the abc
    • Latecomer assertion (after zero-width positive assertion lookbehind)

      • Expression: (? <= Expression)
      • It indicates a position behind the match expression
      • After the assertion made in advance with the implementation of steps to assert the contrary it is this: start with the leftmost character string to match the first one to find abc (that is, an expression first assertion) and then matching expression behind it If the match can not continue abc then find the second match after the second string abc, if the match match
      • For example, (? <= Abc). * Can match abcdefg in defg
    • Negative assertion

      • Negative first assertion :( ?! expression to zero width)
      • After the negative zero-width assertion made: (?! <Expression)

      • Negative zero-width assertion (?! Expression) is a zero-width matching position, but the position of "assertion" take the expression of anti-values, for example, (?! Expression) expression that represents the front of the location, if the expression does not hold, that matches this position; if the expression is established, no match: Again, there are negative "first" and "latecomer" in two to zero-width assertion, the negative zero-width assertion is made (<expression?!)

Guess you like

Origin www.cnblogs.com/he-qing-qing/p/11331080.html