The Match Object: Your Window into Regex Results
When a regex function like re.search() or re.match() successfully finds a pattern, it doesn't just return True; it returns a Match object. This object is a rich container holding all the information about the match, including the specific substrings captured by groups.
Extracting Content with group()
The primary method for retrieving matched content is .group(). It accepts an index to specify which capture group you want:
group(0)(or simplygroup()): Returns the entire string that matched the pattern.group(1),group(2), etc.: Returns the content of the corresponding parenthesized capturing group.