由于在使用的时候发现字符串中有些标点被比配,有些则没有被匹配,搜了一下没有找到具体解释,下面就发一些自己测试的结果仅供参考。
#!usr/bin/env python
#-*-coding:utf-8-*-
import string
import re
string1='(3.6.3)fadssa.7/4.'
string2='hello/2017-19-29...//'
string3='hello./.,;'
print(string1.strip(string.punctuation))
print(string2.strip(string.punctuation))
print(string3.strip(string.punctuation))
输出结果如下:
(3.6.3fadssa.7/4
hello/2017-19-29
hello