python使用正则表达式去掉字符串中大括号之间的字符


我的代码是这样的:


 import re
import sys 

s='{通配符}你好,今天开学了{通配符},你好'
print "s", s
a1 = re.compile('\{.*\}' )
d = a1.sub('',s)
print "d",d

我想把 s 中的两个 {通配符}} 给去掉,但是现在的代码执行后 d 只剩下 ,你好 了,请问应该怎么实现我想要的功能呢,这个正则表达式应该怎么写?

python 正则表达式

克劳德史克莱夫 9 years, 9 months ago

 a1 = re.compile('\{.*?\}' )

大象-Mk2 answered 9 years, 9 months ago

Your Answer