#抽取字符串中的数字
import re
re.findall(r'\d+', 'hello 42 a 32 string 30')
#提取字符串中的中文
txt='帮会建了徽信群 没在群里的加下徽信:[30109552300],晚上群里有活动通知大家,(抢资源),争地盘,谢谢配合。i love you '
pre = re.compile(u'[\u4e00-\u9fa5]')
res = re.findall(pre, txt)
res1=''.join(res)
print(res1)
#提取汉字和标点
txt='帮会建了徽信群 没在群里的加下徽信:[30109552300],晚上群里有活动通知大家,(抢资源),争地盘,谢谢配合。i love you '
pre = re.compile(u'[\u4e00-\u9fa5-\,\。]')
res = re.findall(pre, txt)
res1=''.join(res)
print(res1)
提取字符串中指定文字——python
最新推荐文章于 2024-06-04 11:40:31 发布