我在这里遇到了以下代码的问题。
问题在于,即使存在“不存在”,也总是与'是'匹配。
有人可以帮忙吗?
Then I take an argument arg1 and match one of these is not when available
Then /^I take an argument (.+) and match one of these (is not|IS|IS NOT|is) when available$/ do |pram1,pram2|
# do stuff...
end
答案 0 :(得分:-1)
我运行正则表达式并且它对我有用 - 返回"不是"作为比赛。
我还让它不区分大小写(?i)干掉它
irb> "I take an argument arg1 and match one of these is not when available" =~ /^I take an argument (.+) and match one of these (?i)(IS|IS NOT) when available$/
irb> Regexp.last_match.captures
[
[0] "arg1",
[1] "is not"
]