1、使用Python的re模块,re模块提供了re.sub用于替换字符串中的匹配项。
re.sub(pattern, repl, string, count=0)
参数说明:
pattern:正则重的模式字符串
repl:被拿来替换的字符串
string:要被用于替换的原始字符串
count:模式匹配后替换的次数,省略则默认为0,表示替换所有的匹配
2、提取中文,通过将不是中文的字符替换为空就可以了。
实例
import re str = "重出江湖hello的地H方。。的,world" str = re.sub("[A-Za-z0-9\,\。]", "", str) print(str)
查看更多关于Python如何提取字符串的内容的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did182148