perl exact string match

前端 未结 3 1111
忘掉有多难
忘掉有多难 2021-01-19 13:30

I have following Perl code to prompt user for yes/no answer. If the user enters anything else than yes/no, keep prompting. No other word is acceptable. I don\'t know why thi

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-19 13:52

    You should use following Perl regular expression for matching only yes or no (case insensitive):

    m/^(yes|no)$/i
    

    For yes only, use:

    m/^yes$/i
    

提交回复
热议问题