A:匹配字符串的开始
:匹配一个单词边界
取出a边界单词的个数
>>> len(re.findall(r"a"," ab abc add"))
3
B:匹配非单词边界
d:匹配任意一个数字范围【0-9】
- >>> re.match(r"d+","123abc")
- <_sre.SRE_Match object at 0x000000000202A510>
D:匹配任意一个非数字字符== [^d]
- >>> re.match(r"D+","ABC123").group()
- 'ABC'
s:匹配空白字符 练习
>>> print re.match(r"s"," 13d")
<_sre.SRE_Match object at 0x0000000001F1A510>
S:匹配非空白字符
>>> print re.match(r"S","13d")
<_sre.SRE_Match object at 0x0000000001F1A510>
w:匹配单个字符(数字或字母)
>>> print re.match(r"w","13d")
<_sre.SRE_Match object at 0x0000000001F1A510>
w+:匹配多个字符(数字或字母)
>>> print re.match(r"w+","13d")
<_sre.SRE_Match object at 0x0000000001F1A510>
>>> re.match(r"w+","13d")
<_sre.SRE_Match object at 0x0000000001F1A510>
>>> re.match(r"w+","13d").group()
'13d'
>>> re.match(r"D+","13d").group()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
W:非单词字符,等价于[^w]