#!/usr/bin/env python3
import re

batRegex =re.compile(r'Bat(wo)?man')  # means Batman or Batwoman

mo =batRegex.search("The adventure of Batman")


print(mo.group())


mo =batRegex.search("The adventure of Batwoman")

print(mo.group())


phoneRegex =re.compile(r'(\d{3}-)?\d{3}-\d{4}') #first area code is optional, so find either 415-222-2323 or 222-2323

print(phoneRegex.search('My number is 416-222-2323'))
print(phoneRegex.search('My number is 222-2323'))

mo = phoneRegex.search('My number is 416-222-2323')
print(mo.group())

mo = phoneRegex.search('My number is 222-2323')
print(mo.group())

# * zero or more times
# + means one or more
#? means zero or one time
batRegexstar=re.compile(r'Bat(wo)*man')
batRegex =re.compile(r'Bat(wo)?man')

print(batRegexstar.search("Wow it's Batwowowowoman"))
print(batRegexstar.search("Wow it's Batwoman"))
print(batRegex.search("WOW This is Batwowowowman"))
print(batRegex.search("Wow it's Batwoman"))


# + means one or more

batRegex = re.compile(r'Bat(wo)+man') # this means that "wo" has to show up at least once or more. So this will not catch Batman anymore

print(batRegex.search("Batman is in town"))
print(batRegex.search("Batwoman is here too"))
print(batRegex.search(("wow Batwowowowowoman! ")))


#if you want to use *, +, ? as part of regular expression, you can use '\' to find it

regex=re.compile(r'\+\*\?')
print(regex.search('I learned about +*? regex syntax'))

#{exactnumber}
haRegex = re.compile(r'(Ha){3}')
print(haRegex.search('He said "HaHaHa"'))

# range of numbers {1,4} from 1 to 4

digitRegex=re.compile(r'\d{3,5}') # this is a greedy match. it shows up to 5 (the most number)
print(digitRegex.search('123456788'))

digitRegex=re.compile(r'\d{3,5}?') # this is a non-greedy match. it shows up to 3 (the least number)
print(digitRegex.search('123456788'))
