Regex replace (in Python) - a simpler way?

前端 未结 4 466
广开言路
广开言路 2020-12-12 22:16

Any time I want to replace a piece of text that is part of a larger piece of text, I always have to do something like:

\"(?Psome_pattern)(?P<         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 22:58

    Look in the Python re documentation for lookaheads (?=...) and lookbehinds (?<=...) -- I'm pretty sure they're what you want. They match strings, but do not "consume" the bits of the strings they match.

提交回复
热议问题