Python - re.error: unterminated character set at position

后端 未结 1 2569
春和景丽
春和景丽 2021-01-11 13:39

The following code:

text = \"I\'m a string that contains this characters {}, [], ()\"
slice = \"this characters {}, [], ()\"
print([ (m.start(0), m.end(0)) f         


        
相关标签:
1条回答
  • 2021-01-11 14:01

    You must escape the special characters in your regex:

    slice = "this characters \{}, \[], \(\)"
    

    Note that only the opening brace and square bracket need an escape, but both parentheses.

    0 讨论(0)
提交回复
热议问题