""" Author: Samrat Banerjee Dated: 03/05/2018 Description: findall() Method-Only works as long as there are no groups in the regex """ import re phoneNumRegex = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d') mo = phoneNumRegex.search('Cell: 415-555-9999 Work: 212-555-0000') print(mo.group()) print(phoneNumRegex.findall('Cell: 415-555-9999 Work: 212-555-0000')) phoneNumRegex = re.compile(r'(\d\d\d)-(\d\d\d)-(\d\d\d\d)') # has groups print(phoneNumRegex.findall('Cell: 415-555-9999 Work: 212-555-0000')) # Using character classes xmasRegex = re.compile(r'\d+\s\w+') print(xmasRegex.findall('12 drummers, 11 pipers, 10 lords, 9 ladies, 8 maids, 7 swans, 6 geese, 5 rings, 4 birds, 3 hens, 2 doves, 1 partridge'))