python string manipulation

后端 未结 8 2192
生来不讨喜
生来不讨喜 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:15

    Nested brackets (or tags, ...) are something that are not possible to handle in a general way using regex. See http://www.amazon.de/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124/ref=sr_1_1?ie=UTF8&s=gateway&qid=1304230523&sr=8-1-spell for details why. You would need a real parser.

    It's possible to construct a regex which can handle two levels of nesting, but they are already ugly, three levels will already be quite long. And you don't want to think about four levels. ;-)

提交回复
热议问题