"""Run the birthday examples from the regex reading."""

import re

print(re.search(r'birthday', 'Sam has a birthday today'))  # <re.Match object; span=(10, 18), match='birthday'>
print(re.search(r'anniversary', 'Sam has a birthday today'))  # None

if re.search(r'birthday', 'Sam has a birthday today'):
    print('Send a card')  # Send a card

print(re.search(r'\d', 'Sam was born in 1985'))  # <re.Match object; span=(16, 17), match='1'>

print(re.search(r'\d+', 'Sam was born in 1985'))  # <re.Match object; span=(16, 20), match='1985'>

print(bool(re.search(r'[ST][ai]m', 'Tim: 11/01')))  # True
print(bool(re.search(r'birthdays?', 'one birthday this week')))  # True

text = 'Sam: 04/22; Elon: 06/28'
print(re.findall(r'\d{2}/\d{2}', text))  # ['04/22', '06/28']

print(re.findall(r'(\d{2})/\d{2}', text))  # ['04', '06']

print(re.findall(r'(\d{2})/(\d{2})', text))  # [('04', '22'), ('06', '28')]

match = re.search(r'birthday: (\d{2}/\d{2})', 'Sam birthday: 04/22')
if match:
    print(match.group(0))  # birthday: 04/22
    print(match.group(1))  # 04/22

print(re.findall(r'\w+\.csv', 'files: birthdays.csv, friends.csv'))  # ['birthdays.csv', 'friends.csv']

print(bool(re.search(r'birthday', 'Sam has a birthday today')))  # True
print(bool(re.fullmatch(r'birthday', 'Sam has a birthday today')))  # False
print(bool(re.fullmatch(r'birthday', 'birthday')))  # True

date_pattern = r'\d{2}/\d{2}'
print(bool(re.fullmatch(date_pattern, '04/22')))  # True
print(bool(re.search(date_pattern, '04/220')))  # True
print(bool(re.fullmatch(date_pattern, '04/220')))  # False

print(re.sub(r'\s+', ' ', 'Sam   birthday:\t04/22'))  # Sam birthday: 04/22

print(re.sub(r'(\d{2})/(\d{2})', r'\g<2>-\g<1>', text))  # Sam: 22-04; Elon: 28-06
