import re

phoneNumRegex = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d')
phoneNumRegex.search('My number is 415-555-4242') # returns a match object
mo = phoneNumRegex.search('My number is 415-555-4242') # store match object
mo.group() # print matched strings in match object

"""
Explanation: Lesson 24:
RegEx groups and the Pipe Character
Regex can also be used in other ways, such as partial matching.
End of explanation
"""


phoneNumRegex = re.compile(r'(\d\d\d)-(\d\d\d-\d\d\d\d)') # The first () is group 1, the second () is group 2
phoneNumRegex.search('My number is 415-555-4242') # returns a match object with subgroups
mo = phoneNumRegex.search('My number is 415-555-4242') # store match object with subgroups
print('The area code is ' + mo.group(1)) # print out the subgroup matching the parameter
print('The rest of it is ' + mo.group(2)) # print out the other subgroup

"""
Explanation: To get different sections of a string, we can use groups via parenthesis:
End of explanation
"""


phoneNumRegex = re.compile(r'\(\d\d\d\)-\d\d\d-\d\d\d\d')

mo = phoneNumRegex.search('My number is 415-555-4242') # returns no match
print(mo)
mo =phoneNumRegex.search('My number is (415)-555-4242') # returns a match object
mo.group()

"""
Explanation: If parenthesis are actually part of the pattern, they need to be escaped:
End of explanation
"""


batRegex = re.compile(r'Bat(man|mobile|copter|cat)') # The pipe character seperates the suffixes, and allows any match.

mo = batRegex.search('Batmobile lost a wheel.')
print(mo.group()) # Print matching string

print(mo.group(1)) # Pass variable 1 into the group function to find which suffix group actually matched

#mo2 = batRegex.search('Batmotorcycle lost a wheel.')
#mo.group() # will return error because no match

"""
Explanation: The '|' RegEx Operater
The pipe character, |, matches one of several patterns in a group.
End of explanation
"""


