ori = "SDP_123_CC[comments]"
rr = re.compile(r"""(.*) #match the string that will be kept, and will be backreference with number 1
[\[\(] #match [ or (
[^\[\]\(\)]* #match anything but not "[]()"
[\]\)]$""",re.X) #match the last ) ]
print re.sub(rr,"\\1",ori)
如果括号或方括号内只有数字或字符,您可以使用:
相关问题 更多 >
编程相关推荐