name: Ann
Address: BUPT
"""
#p = re.compile(r"^name:(.*) ^Address:(.*) ", re.M)
p = re.compile(r"^name:(?P<name>.*) ^Address:(?P<address>.*) ", re.M)
for m in p.finditer(x):
print m.span()
print "here is your friends list"
print "%s, %s"%m.groups()
Compile Flag
用re.compile得到RegxObject时,可以有一些flag用来调整RegxObject的详细特征.
DOTALL, S 让.匹配任意字符,包括换行符
IGNORECASE, I 忽略大小写
LOCALES, L 让\w \W \b \B和当前的locale一致
MULTILINE, M 多行模式,只影响^和$(参见上例)
VERBOSE, X verbose模式