Python split string without splitting escaped character

后端 未结 10 1373
谎友^
谎友^ 2020-12-08 20:56

Is there a way to split a string without splitting escaped character? For example, I have a string and want to split by \':\' and not by \'\\:\'

http\\://ww         


        
10条回答
  •  一整个雨季
    2020-12-08 21:30

    building on @user629923's suggestion, but being much simpler than other answers:

    import re
    DBL_ESC = "!double escape!"
    
    s = r"Hello:World\:Goodbye\\:Cruel\\\:World"
    
    map(lambda x: x.replace(DBL_ESC, r'\\'), re.split(r'(?

提交回复
热议问题