Find the indexes of all regex matches?

前端 未结 3 1978
不思量自难忘°
不思量自难忘° 2020-11-28 05:00

I\'m parsing strings that could have any number of quoted strings inside them (I\'m parsing code, and trying to avoid PLY). I want to find out if a substring is quoted, and

3条回答
  •  离开以前
    2020-11-28 05:26

    This should solve your issue pattern=r"(?=(\"[^\"]+\"|'[^']+'))"

    Then use the following to get all overlapping indices,

    indicesTuple=[(mObj.start(1),mObj.end(1)-1) for mObj in re.finditer(pattern,input)]

提交回复
热议问题