findall()import re
mouhaRegex = re.compile(r'mou(Ha){4}')
mo1 = mouhaRegex.search('mouHaHaHaHa')
print(mo1.group())
mo2 = mouhaRegex.search('mouHaHa')
if mo2 == None:
print('Pattern not found')
import re
greedyHaRegex = re.compile(r'(Ha){3,5}')
mo1 = greedyHaRegex.search('HaHaHaHaHa')
print(mo1.group())
nonGreedyHaRegex = re.compile(r'(Ha){3,5}?')
mo2 = nonGreedyHaRegex.search('HaHaHaHaHa')
print(mo2.group())
findall()import re
phoneRegex = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d')
mo = phoneRegex.search('Cell: 415-555-9999 Work: 212-555-0000')
print(mo.group())
print(phoneRegex.findall('Cell: 415-555-9999 Work: 212-555-0000'))
phoneRegex = re.compile(r'(\d\d\d)-(\d\d\d)-(\d\d\d\d)')
print(phoneRegex.findall('Cell: 415-555-9999 Work: 212-555-0000'))
Nous avons vu dans ce cours :
findall()