From: dblack@... Date: 2003-10-09T20:08:23+09:00 Subject: Re: case where regex range should raise Hi -- On Thu, 9 Oct 2003, Robert Klemme wrote: > > Interestingly enough negative values do not cause errors but do not match > either: > > irb(main):008:0> /f{-1,2}/ =~ "aaffff" > => nil > > IMHO this should either raise an error or match, since there are more > than -1 "f"'s in the string. This is also similar to the case Guy showed: irb(main):004:0> /a{-1,2}/.match("a{-1,2}")[0] => "a{-1,2}" However.... irb(main):005:0> /{-1,2}/.match("{-1,2}")[0] SyntaxError: compile error (irb):5: invalid regular expression; there's no previous pattern, to which '{' would define cardinality at 1: /{-1,2}/ So apparently if a { is encountered, the algorithm is: 1. is there a previous pattern to apply it to? a. no: error b. yes: is it a plausible {} range? i. yes: apply it ii. no: treat it as a literal string One might argue that 1b should come first. David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav