删除字符串中括号内的内容

时间:2016-12-21 08:48:08

标签: python regex string

我想用字符串中的括号删除括号和内容。 我尝试了以下代码:

a['Street Name'].str.replace('\(.*)','')

但它不起作用。有人可以告诉我这个陈述有什么问题吗?

1 个答案:

答案 0 :(得分:1)

试试这个:

import re

s = "I want to remove all words in brackets( like (this) and ((this)) and ((even) this))."

while True:
    s_new = re.sub(r'\([^\(]*?\)', r'', s)
    if s_new == s:
        break
    s = s_new

print(s_new) # I want to remove all words in brackets.
相关问题