求Python正则匹配高手帮我查下源码问题在哪里,python源码,代码如下:content


代码如下:

content = "\">123|abc"pattern = re.compile(r'>(?P<username>[a-zA-Z0-9]+)\|(?P<password>[a-zA-Z0-9]+)',re.I|re.S) match = pattern.match(content)        username = match.group("username")password = match.group("password")

为何以上的正则表达式,没法匹配到数据呢?
如果正则改成

.*?>(?P<username>[a-zA-Z0-9]+)\|(?P<password>[a-zA-Z0-9]+)

这样就可以了,但是这样容易误报

这个真的要说“好好去看文档(RTFM)”了……

RegexObject.match()要求匹配内容出现在字符串的开头(beginning),.search()才是任意位置。

编橙之家文章,

评论关闭