Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3624635
  • 博文数量: 880
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 6155
  • 用 户 组: 普通用户
  • 注册时间: 2016-11-11 09:12
个人简介

To be a better coder

文章分类

全部博文(880)

文章存档

2022年(5)

2021年(60)

2020年(175)

2019年(207)

2018年(210)

2017年(142)

2016年(81)

分类: LINUX

2019-03-13 15:13:55

[root@localhost /]# cat a.py
#!/bin/python
import re
s = '1102231990xxxxxxxx'
res = re.search('(?P\d{3})(?P\d{3})(?P\d{4})',s)
ret = re.findall('(?P\d{3})(?P\d{3})(?P\d{4})',s)
print(res.groupdict())
print(ret)
[root@localhost /]#

数量词{1,2}
非贪婪{1,2}?
* 号 前面的字符匹配0次或无限多次
+号 前面的字符匹配一次或无限多次
?号前面的字符匹配0次或一次
边界匹配^    $
以上都是指的字符,下面介绍组
组的概念()
[root@localhost /]# cat str.py
#!/bin/python
import re
a='python 1111java678php'
b=re.findall('[a-z]{3,6}?',a)
print b
c='pytho0python1pythonn2'
d=re.findall('python*',c)
e=re.findall('python+',c)
f=re.findall('python?',c)
g=re.findall('python{1,2}?',c)
print d
print e
print f
print g
u='123456'
h=re.findall('^\d{4,8}$',u)
print h
p='pythonpythonpython'
q=re.findall('(python){2}',p)
print q
[root@localhost /]#
#!/bin/python
import re
a='python 1111yyyyjava222php'
b='pytho0python1pythonn2'
print re.findall('[a-z]',a)
print re.findall('[a-z]{3}',a)
print re.findall('[a-z]{3,6}',a)
print re.findall('[a-z]{3,6}?',a)
print re.findall('python*',b)
print re.findall('python+',b)
print re.findall('python?',b)
阅读(4584) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~