Francis Hwang
11/18/2004 4:36:00 AM
On Nov 17, 2004, at 10:55 PM, James Edward Gray II wrote:
> On Nov 17, 2004, at 9:47 PM, Francis Hwang wrote:
>
>> Is this behavior a bug, or am I misunderstanding how I should make a
>> regexp?
>>
>> irb(main):001:0> str = "123.456.*"
>> => "123.456.*"
>> irb(main):002:0> str =~ /^[0123456789.-*]+/
>> SyntaxError: compile error
>> (irb):2: empty range in char class: /^[0123456789.-*]+/
>> from (irb):2
>> irb(main):003:0> str =~ /^[0123456789*.-]+/
>> => 0
>
> - is a special character inside a Regexp character class. It means,
> from this (character left of dash) to this (character right of dash).
> It's usually used to say A-Z, a-z, 0-9, or similar. Putting it at the
> beginning or end of a class negates this special meaning, thus the
> change in the second attempt.
Ah, of course. I fixated on the * and totally forgot about what the -
was doing. Thanks.
F.