Python regex: substitute all occurrence of a certain string NOT after a specific character

前端 未结 2 1888
猫巷女王i
猫巷女王i 2021-01-27 07:51

How can I substitute all occurrence of a certain string NOT after a specific character in Python?

For example, I want to substitute all occurrence of abc NO

2条回答
  •  自闭症患者
    2021-01-27 08:47

    With a negative lookbehind assertion (? (i.e. not preceded by):

    (?

    In a replacement:

    re.sub(r'(?

提交回复
热议问题