re.sub not replacing all occurrences

前端 未结 4 1983

I\'m not a Python developer, but I\'m using a Python script to convert SQLite to MySQL

The suggested script gets close, but no cigar, as they say.

The line g

4条回答
  •  自闭症患者
    2021-01-02 02:26

    The two substitutions you'd want in your example overlap - the comma between your two instances of 't' will be matched by (.) in the first case, so ([^']) in the second case never gets a chance to match it. This slightly modified version might help:

    line = re.sub(r"(?

    This version uses lookahead and lookbehind syntax, described here.

提交回复
热议问题