Regex - lookahead assertion -


I have a problem with letterhead assurance (? =) For example, I have the expression:

  / win (? = 2000) /  

matches this win , if there is an expression like Win2000 , < Code> Win2000fgF . I have the next expression:

  ^ (? =. * \ D) (? =. * [Az]). * $  

This is for a match and lower case letter, for example: 45dF , 4Dd . But I do not know, why does this work and match all the characters :) I do not have letters, which are before (? =. * * * D) I think, this expression should only work:

  ^. * * (? =. * \ D) (? =? * [Az]). * $  

( \ * before expression)

Can you explain it to

Suppose we are regex engines and applicable Are ridge x ^ (? =. * \ D) (? =. * [Az]). * $ string 2A .

OK

  • (? = : Check if the following Reggae can match ...
  • . * : any Match the characters in the number -> 2a . OK.
  • \ d : No, we are already in the end. Back: a -> does not match any other: 2 -> match!
  • ) : look-alike Finally, successful match we are still Status 0!
  • (? = : Check if the following regenges can match ...
  • . * : any of the letters Also corresponds to the number -> 2a . OK.
  • [az] : No, we return a word: A -> match!
  • ) : the end of the Lookahhead, the match is successful we still are in position 0!
  • . * : Match any number of characters -> 2a -> match!
  • $ : See - are we at the end of the string? Yes we are! -> match!
  • Hey, we've reached the end of the regex. great. Match completed!

  • Comments