断言

断言有三种:单词边界 其实行 环视

单词边界:

单词边界的匹配:

print re(r"w+", "a sentence contains a lots of words")

单词边界匹配的高亮:

print re(r"row", "a sentence contains a lots of words")

行起始/结束位置:

行终止符:Linux windows OS

提取每行的第一个单词:

多行模式:(?m)

提取每行的第一个单词:

print re.findall(r"(?m)^w+", "first line second line last line")

匹配整段文本的第一个单词:

print re.findall(r"(?m)Aw+", "first line second line last line")

匹配整段文本的最后一个单词:

print re.findall(r"(?m)w+$", "Some sample text")

w+$ 匹配每一行的最后一个单词。