crystal
crystal copied to clipboard
`Regex` match methods do not accept negative position
A negative index into a string usually means to start counting from the end ("foo"[-2..] == "oo"
). This does not work for Regex
's match methods though: /oo/.match("foo", -2) == nil
.
I think it makes sense to add this to the implementation for consistency.
Regex#match
depends on String#char_index_to_byte_index
which doesn't support negative arguments. Not sure about the rest of Regex
though
Btw. the equivalent works in Ruby: /oo/.match?("foo", -2) # => true
There are actually two notions of an index; character indices depend on String
as mentioned above, byte indices should only require single-line additions to Regex#match_at_byte_index
and #matches_at_byte_index?
.