address = input("Please input the drivers home address (e.g. EH129DN): ")
addresspattern = "[A-Z][A-Z]/d/d/s/d[A-Z][A-Z]"
match = re.search(address, addresspattern)
if match:
Continue = input ("Do you wish to continue? (Y/N): ")
我不知道为什么这不起作用,但它肯定是正则表达式
Tags:
尝试:
因为
re.search
模式是第一个参数。EH129DN
不包含任何空格,因此不需要\s
尝试使用原始输入代替输入
输入和原始输入之间的差异Differences between `input` and `raw_input`
为了让您开始,您可以按以下方式对其进行重组:
提供以下类型的输出:
注意,如果您试图匹配所有有效的邮政编码,那么您将需要研究一个更重要的正则表达式。我保留了您现有的逻辑,但它现在允许在两者之间留有可选的空间。另外,我还使用了
raw_input()
,因为您需要文本输入相关问题 更多 >
编程相关推荐