如果里面的内容是数字,去掉括号

Remove brackets if the content inside is a number

如果.isnumeric()

里面的内容有没有什么办法去掉括号()

我知道一点 RegEx,但我找不到使用 RegEx 的方法。

示例:

input = '((1)+(1))+2+(1+2)+((2))'
output = somefunction(input)

这里的输出应该是这样的

(1+1)+2+(1+2)+2
import re

x = '((1)+(1))+2+(1+2)+((2))'
re.sub(r'(\()([\d*\.]+)(\))', r"", x)

"""
or
re.sub(r'\(([\d*\.]+)\)', r"", x) #  @deceze
"""

但这会给你 (1+1)+2+(1+2)+(2)

也许可以使用 re.subn 来执行此操作,直到替换次数为 0