This topic created in 3489 days ago, the information mentioned may be changed or developed.
import re
s='aabbaa'
s 字符串或有 4 个字符 a.
md=re.search('a',s) #但 search()返回的是 s 字符串中第一匹配到的 match 对象
fa=re.findall('a',s) #这个findall()找到了所有4个匹配,但返回的是匹配得到的字符串,而不是match对象.
mds=re.scan('a',s) #我想得到全部 4 个匹配到的 match 对象,但是 python 没有 scan()方法?该怎么办呢?
如果自己手动实现,是可以的,但我想这是个很常用的功能,python 不会不内置解决方法吧?
请各位指点!
2 replies • 2016-10-14 08:58:24 +08:00
 |
|
1
binux Oct 13, 2016 1
re.finditer
|
 |
|
2
Cabana Oct 14, 2016
用 pattern find
|