How do I find the shortest overlapping match using regular expressions?

前端 未结 9 1119
無奈伤痛
無奈伤痛 2020-12-15 08:03

I\'m still relatively new to regex. I\'m trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a sub

9条回答
  •  悲&欢浪女
    2020-12-15 08:29

    No. Perl returns the longest, leftmost match, while obeying your non-greedy quantifiers. You'll have to loop, I'm afraid.

    Edit: Yes, I realize I said Perl above, but I believe it is true for Python.

提交回复
热议问题