"foo = '@test.bar';\nfooa = @test.darn;".match(/@([a-z][a-z\.-_]*)/igm)
Why does this match
["@test.bar", "@test.darn;"]
rather than just
["@test.bar", "@test.darn"]
?
In character classes, some letters have special meanings. The dot for example has none and does not need to be escaped. The minus in contrast defines a range of characters, and if you mean literally minus you need to escape it or put it in the end/beginning of the character class. Your range from . to _ actually includes ./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_. You may want to use [a-z.\-_] or [a-z._-] instead.
[] has to be escaped inside. The - needs to be escaped because it has special meaning inside [].^ has to be escaped inside a character class as well.^ has special meaning inside [] so it has to be escaped, and ] well I think that one seems pretty obvious...
.to_includes;but not'\walso includes\d\is actually included in that range as well, so the\in the OP's question is doubly redundant.-as well, so it wasn't a range anyway.