您不需要正则表达式即可执行此任务。使用
str.strip有
string.punctuation:
>>> import string>>> string.punctuation'!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~'>>> '!Hello.'.strip(string.punctuation)'Hello'>>> ' '.join(word.strip(string.punctuation) for word in "Hello, world. I'm a boy, you're a girl.".split())"Hello world I'm a boy you're a girl"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)