From: "Jesús Gabriel y Galán" Date: 2008-06-30T16:10:46+09:00 Subject: Re: Statistician I (#167) On Mon, Jun 30, 2008 at 3:19 AM, Matthew Moss wrote: > > > On Jun 29, 3:19 pm, Matthew Rudy Jacobs > wrote: >> Matthew Moss wrote: >> >> > def initialize(str) >> > patt = str.gsub(/\[(.+?)\]/, '(?:\1)?').gsub(/<(.+?)>/, '(.+?)') >> > @pattern = Regexp.new('^' + patt + '$') >> > @fields = nil >> > end >> >> does the rule string not need to be regexp escaped somehow if it's >> gonna be directly Regexp.new'ed? >> >> I fear a rule with something like "You run away[ from ] (you >> coward)" would break this approach. > > > Perhaps... My solution is likely not safe from all input sets. While I > hadn't considered literal parentheses as part of the rule set, I > should have at the least considered the period (match any char). > > For the current purposes, it is sufficient if your solution supports > the provided example ruleset, though any additional work towards > escaping parts/preventing breakage is certainly acceptable. I had to escape the string in order to make my solution work due to the final dot... Jesus.