Linked Questions

Popular Questions

Are regular expression match group(0) & group() the same?

Asked by At
import re

a = "AB01"
m = re.compile(r"([A-Z]{2})(\s?_?\s?)([0-9]{2})")  # note raw string
g = m.match(a)
if g:
  g = m.match(a).group(1) + "-" +
  print m.match(a).group()
  print m.match(a).group(0)
  print (m.match(a).group(0) == m.match(a).group())
  print g

In the above code, is the whole match of the group m.match(a).group(), is that the same as m.match(a).group(0)? If so, which is the preferred use?

Related Questions