当前位置:主页 > 软件编程 > Python代码 >

python3正则提取字符串里的中文实例

时间:2021-05-12 09:10:28 | 栏目:Python代码 | 点击:

如下所示:

# -*- coding: utf-8 -*-
import re
#过滤掉除了中文以外的字符
str = "hello,world!!%[545]你好234世界。。。"
str = re.sub("[A-Za-z0-9\!\%\[\]\,\。]", "", str)
print(str)
 
#提取字符串里的中文,返回数组
pattern="[\u4e00-\u9fa5]+" 
regex = re.compile(pattern)
results = regex.findall("adf中文adf发京东方")
print(results)

打印结果:

python3正则提取字符串里的中文

您可能感兴趣的文章:

相关文章