假设我有以下地址数组
array = ["1 New Street, Filton Grove, Bristol BD7 0AA", "2 New Street, Filton Grove, Bristol BD7 0AA", "3 New Street, Filton Grove, Bristol BD7 0AA"]
我想检查数组中的每一项是否都包含单词 Filton Grove Bristol
,但由于地址中有逗号,这让我有点困惑。
如何忽略逗号并检查每个单词是否存在于数组的每次迭代中
到目前为止我有这个
regexp = /^Filton Grove Bristol/i
array.all? { |a| regex =~ a }
但这失败了。
最佳答案
您可以单独检查单词。
regexp_checks = [/Filton/i, /Grove/i, /Bristol/i]
array.all? { |a| regexp_checks.all?{|rgx| a =~ rgx} }
关于ruby - 正则表达式匹配多个字符串 - Ruby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29623061/