Python正则表达式-match对象使用group和groups提取时的区别

Python正则表达式-match对象使用group和groups提取时的区别,第1张

  • group()
    获取到的是匹配到的整体内容
  • groups()
    获取到分组后的内容,以元组形式输出
    示例:
text = 'id=1711349'
match_object = re.match("(id|key)=(\w+)", text.strip())
v1 = match_object.group() # "id=1711349" 
name,value = match_object.groups() # ("id","1711349")

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/798480.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存