Regexp warning

I've upgraded to ruby2.1.0 and tried it on my program and I got a
warning:

IFMapper/IFMReader.rb:102: warning: character class has duplicated
range: /^\s*[\w_\-\.]+\s*=.*$/

It seems ruby2.1.0 is understanding the - sign as a range instead of
using the backslash to treat the - as a minus sign only.

···

--
Posted via http://www.ruby-forum.com/.

Not seeing a warning with that expression on 2.1.0. What is the context of that code?

Anyway, if you are indeed seeing a warning, I don’t think that it’s caused by the - (minus). The \w includes the _ (underscore), so if you’re getting a duplication warning it is most probably caused by that.

FYI, you can place the - (minus) at the beginning or the end of the set (without escaping it). It will not be treated as part of a range in those cases.

Regards,
Ammar

···

On Jan 20, 2014, at 7:18 PM, Gonzalo Garramuno <lists@ruby-forum.com> wrote:

I've upgraded to ruby2.1.0 and tried it on my program and I got a
warning:

IFMapper/IFMReader.rb:102: warning: character class has duplicated
range: /^\s*[\w_\-\.]+\s*=.*$/

It seems ruby2.1.0 is understanding the - sign as a range instead of
using the backslash to treat the - as a minus sign only.