【发布时间】:2020-03-08 08:36:04
【问题描述】:
在Python中很幼稚,在Python中学习re模块时,我发现了一些奇怪的东西(我无法得到它):
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)
输出:
['123-456-7894', '789-456-1235']
batman
batwoman
['', 'wo']
print(bat_list_all)怎么没给列表['batman','batwoman']?我想了解什么?
【问题讨论】:
标签: python regex python-3.x