Being naive in Python, While learning re module in Python, I found something strange (I am not able to get it) :
import re
pattern = re.compile(r'[0-9]{3}-[0-9]{3}-[0-9]{4}')
list_phoneNumbers = pattern.findall('phone number : 123-456-7894, my home number : 789-456-1235')
print(list_phoneNumbers)
pattern = re.compile(r'bat(wo)?man')
batman_match = pattern.search('batman is there')
batwoman_match = pattern.search('batwoman is there')
bat_list_all = pattern.findall('batman is there but not batwoman')
print(batman_match.group())
print(batwoman_match.group())
print(bat_list_all)
Output :
['123-456-7894', '789-456-1235']
batman
batwoman
['', 'wo']
How come print(bat_list_all)
, did not give list ['batman', 'batwoman']? What I am missing to understand?