+ PYTHON REGEX

Python regex - note to self

Non capturing groups

non capturing groups are defined with ?: in the beginning of a group

import re

pattern = re.compile(r'^(\d{3})(?:-|\.)\d{3}(?:-|\.)(\d{4})$')


s_list = [  '123-456-7890',
            '673.999.7890',
            '543.356-1112',
            '543_356-1112' ]

for s in s_list:
    m = re.match(pattern, s)

    if m:
        print m.group()
        print m.groups()