python re any character code example
Example 1: python regex search group
>>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
>>> m[0]
'Isaac Newton'
>>> m[1]
'Isaac'
>>> m[2]
'Newton'
Example 2: python re compile
import re
prog = re.compile(pattern)
result = prog.match(string)
result = re.match(pattern, string)
Example 3: python named group regex example
>>> re.search(r'(?P<name>[^-]+)-(?P<ver>\d.\d.\d-\d+).tar.gz', 'package_name-1.2.3-2004.tar.gz').groupdict()
{'name': 'package_name', 'ver': '1.2.3-2004'}