Python regular expression to remove parentheses and square brackets in a string

Experience: the role of \ in regular expressions-for example:
a single dot in the regular represents any character. When we want to match the dot, we need to use \, that is, pass'\.' to the regular expression to escape , Otherwise, an error will occur.

# 针对括号(全/半角)
string  = "本实用新型公开了全自动套鞋机,在机架(1)内安装鞋套弹性进给装置构成套鞋机,在机架(1)的中间安装滑杆(2)"
res= re.sub(u"\\(.*?\\)|\\{.*?}|\\[.*?]", '', string  )	# 全角字符
# name = re.sub(u"\\(.*?\\)|\\{.*?}|\\[.*?]", '', str)	# 半角字符
print(res)

Guess you like

Origin blog.csdn.net/tailonh/article/details/114918602