Python regex: Following lookahead with quantifier

后端 未结 1 1904
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 10:11

Just trying to wrap my mind around this question, which occurred to me while I was messing around with positive lookaheads.

Does this regex make any sense?



        
相关标签:
1条回答
  • 2021-01-27 10:18

    There is no reason to use the + quantifier here. Regular expression lookaheads and lookbehinds don't actually match any text, which means that if they match once in a position they will "match" an infinite number of times in a row. It seems python is smart enough not to try matching the lookahead more than once, as it does not get caught up in an infinite loop.

    In other words, just stick with unqualified lookaheads: foo(?=bar) is best.

    0 讨论(0)
提交回复
热议问题