python group code example
Example 1: python re compile
import re
prog = re.compile(pattern)
result = prog.match(string)
result = re.match(pattern, string)
Example 2: 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'}
Example 3: group by list python
values = set(map(lambda x:x[1], mylist))
newlist = [[y[0] for y in mylist if y[1]==x] for x in values]
Example 4: python re.search()
match = re.search(r'bb', 'aabbcc')
match = re.search(r'cd', 'aabbcc')
match = re.search(r'...c', 'aabbcc')
match = re.search(r'\d\d\d', 'p123g')
match = re.search(r'\w\w\w', '@@abcd!!')