Replace a string located between

前端 未结 4 2022
说谎
说谎 2020-12-06 05:03

Here is my problem: in a variable that is text and contains commas, I try to delete only the commas located between two strings (in fact [ and ]).

4条回答
  •  离开以前
    2020-12-06 05:33

    You can use an expression like this to match them (if the brackets are balanced):

    ,(?=[^][]*\])
    

    Used something like:

    re.sub(r",(?=[^][]*\])", "", str)
    

提交回复
热议问题