1、匹配一行文字中的所有开头的字母内容
#coding=utf-8
import re
s=“i love you not because of who you are, but because of who i am when i am with you”
content=re.findall(r"\b\w",s)
print content
c:\Python27\Scripts>python task_test.py
[‘i’, ‘l’, ‘y’, ‘n’, ‘b’, ‘o’, ‘w’, ‘y’, ‘a’, ‘b’, ‘b’, ‘o’, ‘w’, ‘i’, ‘a’, ‘w’, ‘i’, ‘a’, ‘w’, ‘y’]
2、匹配一行文字中的所有开头的数字内容
import re
s=“i love you not because 12sd 34er 56df e4 54434”
content=re.findall(r"\b\d",s)
print content
c:\Python27\Scripts>python task_test.py
[‘1’, ‘3’, ‘5’, ‘5’]
3、匹配一行文字中的所有开头的数字内容或数字内容
>>> print re.match(r"\w+",“123sdf”).group()
123sdf
4、 只匹配包含字母和数字的行
#coding=utf-8
import re
s=“i love you not because\n12sd 34er 56\ndf e4 54434”
content=re.findall(r"\w+",s,r