python 正则表达式 锚字符
^ 行首匹配,和[]里的不是一个意思
$ 行尾匹配
\A 匹配字符串开始,他和^区别是:\A他只匹配整个字符串的开头,即使在re.M模式下,他也不会匹配它行的行首
\Z 匹配字符串结束,他和$区别是:\Z他只匹配整个字符串的结束,即使在re.M模式下,他也不会匹配它行的行尾
\b 匹配一个单词的边界(单词的最后一个字符串,单词后面有空格也可以匹配),也就是这单词和空格之间的位置
\B 匹配非单词的边界,
import re
print(re.findall("^sunck","sunck is a good man sunck\nsunck is a nice man",re.M))
print(re.findall("\Asunck","sunck is a good man\nsunck is a nice man",re.M))
print(re.findall("man$","sunck is a good man\nsunck is a nice man",re.M))
print(re.findall("man\Z","sunck is a good man\nsunck is a nice man",re.M))
print(re.search(r"er\b","never"))
print(re.search(r"er\b","nerve"))
print(re.search("er\B","never"))
print(re.search("er\B","nerve"))