From: Matthew Moss Date: 2008-06-30T10:19:35+09:00 Subject: Re: Statistician I (#167) 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.