python string manipulation

后端 未结 8 2269
生来不讨喜
生来不讨喜 2021-01-18 13:29

I have a string s with nested brackets: s = \"AX(p>q)&E((-p)Ur)\"

I want to remove all characters between all pairs of brackets and

8条回答
  •  渐次进展
    2021-01-18 14:11

    Yeah, it should be:

    >>> import re
    >>> s = "AX(p>q)&E(qUr)"
    >>> p = re.compile("\(.*?\)", re.DOTALL)
    >>> new_string = p.sub("", s)
    >>> new_string
    'AX&E'
    

提交回复
热议问题