码迷,mamicode.com
首页 > 编程语言 > 详细

python中使用正则

时间:2020-02-25 19:45:11      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:alt   asd   dfa   pytho   src   span   code   查找   import   

import re

text = "123123aoasasdfaisdfs阿瑟东阿瑟东佛阿迪斯发到付撒大沙发"
# 查找所有的数字
nums = re.findall(r‘\d+‘, text)
print(nums)
# 查找所有的单词
words = re.findall(r‘[a-zA-Z]+‘, text)
print(words)
# 查找所有的汉字
chinese_word = re.findall(r‘[\u4e00-\u9fa5]+‘, text)
# chinese_word = re.findall(r‘[\u4e00-\u9fa5]{4, 10}‘, text)
# chinese_word = re.findall(r‘[\u4e00-\u9fa5]{10}‘, text)
print(chinese_word)

技术图片

 

python中使用正则

标签:alt   asd   dfa   pytho   src   span   code   查找   import   

原文地址:https://www.cnblogs.com/ldlx-mars/p/12363262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!