【发布时间】:2021-03-19 22:04:57
【问题描述】:
我正在尝试搜索字符串数组 (new_string) 并检查它是否包含任何“运算符”
我哪里错了?
def example
operators = ["+", "-"]
string = "+ hi"
new_string = string.split(" ")
if new_string.include? Regexp.union(operators)
print "true"
else
print "false"
end
end
【问题讨论】:
-
你在问一个strings数组是否包含一个特定的regexp。显然,这总是错误的,因为您的数组不包含正则表达式,它包含字符串。