python re pattern class definitions code example
Example 1: python regex search group
>>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
>>> m[0] # The entire match
'Isaac Newton'
>>> m[1] # The first parenthesized subgroup.
'Isaac'
>>> m[2] # The second parenthesized subgroup.
'Newton'
Example 2: re python3
import re
>>> m = re.search('(?<=abc)def', 'abcdef')
>>> m.group(0)
'def'