【发布时间】:2011-10-14 10:37:42
【问题描述】:
我正在尝试将字符串从一个函数传递到另一个函数以作为正则表达式进行解析。
目前,当我这样做时
@match = run_rule({ "subjectline" => "What is the weather like in Mumbai?", "rule" => "[w|W]hat is the weather( like)? in ([^?]+)?"})
答案就是我想要的(匹配正则表达式的各个部分)。
当我这样做时
@match = run_rule({ "subjectline" => "What is the weather like in Mumbai?", "rule" => rule['rule']['rule']})
rule 从 YAML 返回的位置
---
rule:
rule: "[w|W]hat is the weather( like)? in ([^?]+)?"
puts 在控制台返回完全相同的东西
puts rule['rule']['rule']
puts "[w|W]hat is the weather( like)? in ([^?]+)?"
发生了什么事?
【问题讨论】:
-
您可以从字符串ruby-doc.org/core/classes/Regexp.html#M001228构建正则表达式
-
顺便说一句,你打算匹配
|hat is the weather in foo?吗?因为确实如此。您可能只希望[wW]作为您的角色类。 -
问题概要:一些未显示的代码不起作用。怎么回事?
标签: ruby-on-rails ruby ruby-on-rails-3 yaml