Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
bd=raw_input('Enter your birthday(Use "." to seperate between day,month and year): ') for match in re.finditer('/.',bd): print "found"
当我写“12.3.1990”时,以下代码应该打印两次,但它什么也没打印我似乎找不到问题,有人可以帮助我吗?谢谢!
您需要使用反斜杠来转义.运算符并匹配文字.:
.
for match in re.finditer('\.', bd):
您的代码查找文字正斜杠和除换行符以外的任何其他字符。
演示:
>>> import re >>> list(re.finditer('\.', '2013.10.29')) [<_sre.SRE_Match object at 0x100e8ad98>, <_sre.SRE_Match object at 0x100eaf308>]