• group(num=0)

匹配的整个表达式的字符串,group() 可以一次输入多个组号,在这种情况下它将返回一个包含那些组所对应值的元组。

  • groups()

返回一个包含所有小组字符串的元组,从 1 到 所含的小组号。

>>> var2 = "Welcome 44 72"
>>> match = re.search(r'Welcome (\d+) (\d+)',var2)
>>> match.groups()
('44', '72')
>>> match.groups(0)
('44', '72')
>>> match.groups(1)
('44', '72')
>>> match.group(0)
'Welcome 44 72'
>>> match.group(1)
'44'

by Sivaprasad @stackoverflow

相关文章:

  • 2021-11-28
  • 2022-12-23
  • 2021-05-15
  • 2021-09-28
  • 2022-12-23
猜你喜欢
  • 2021-04-17
  • 2021-08-17
  • 2021-06-26
  • 2021-08-29
  • 2021-10-04
  • 2022-12-23
  • 2021-06-06
相关资源
相似解决方案