From: Christopher Schneider Date: 2006-12-07T07:44:08+09:00 Subject: Re: Why is this regex invalid? I'm pretty sure the dash needs to be escaped in regular expressions. The second one works since it is the last character in the character class, and hence isn't defining a range. /([0-9]*)([^\+\- ]+)(.*)/ should work - note the escaped dash. -Chris Schneider On Dec 6, 2006, at 3:38 PM, Daniel Finnie wrote: > irb(main):002:0> regex = /([0-9]*)([^\+- ]+)(.*)/ > SyntaxError: compile error > (irb):2: invalid regular expression: /([0-9]*)([^\+- ]+)(.*)/ > from (irb):2 > > irb(main):003:0> regex = /([0-9]*)([^\+ -]+)(.*)/ > => /([0-9]*)([^\+ -]+)(.*)/ > > The only thing that it different in the 2 regexps is the placement > of the space in the square brackets, yet the first regexp is > invalid and the 2nd valid. > > Why is this? > > Thanks, > Dan