从文档中可以清楚地看出:
match()
- >在字符串的开头应用模式匹配search()
- >搜索字符串并返回第一个匹配项并search
有'^'
和没有re.M
标志会的工作一样match
.
那为什么python有match()
?这不是多余的吗?保持match()
python 是否有任何性能优势?
当我在python 2.7中运行以下语句时,
re.search('eagle|cat', 'The cat is an animal. The eagle is bird').group()
Run Code Online (Sandbox Code Playgroud)
我希望'eagle'
按照正则表达式doc 看到结果但是我得到了'cat'
.我在这里错过了什么吗?