Understanding negative lookahead

前端 未结 4 702
粉色の甜心
粉色の甜心 2020-12-05 23:01

I\'m trying to understand how negative lookaheads work on simple examples. For instance, consider the following regex:



        
4条回答
  •  情歌与酒
    2020-12-05 23:05

    So, in that case the regex matches any string that contains strictly 3 characters and is not the abc

    This is not quite right. This regex states that we are searching a sequence which firstsymbol is a and after that is c, and inside there is no b.

    For example, a(?!b). will match either ac or af as there is no restrictions on the last symbol via .

提交回复
热议问题