我有一个程序需要输入“是”,例如:
my_input = raw_input('> ')
if my_input == 'yes':
#etc
Run Code Online (Sandbox Code Playgroud)
但这太具体了,我希望输入与此正则表达式匹配:[yY](es)?,以便如果用户输入“是,是,y 或 Y”,则是相同的。但我不知道这是如何在 python 中实现的。
我想要这样的东西:
regex = some.regex.method('[yY](es)?')
my_input = raw_input('> ')
if my_input == regex:
#etc
Run Code Online (Sandbox Code Playgroud)
先感谢您。