[DOC] How to get the longest last match [Bug #18415]

This commit is contained in:
Nobuyoshi Nakada 2021-12-19 20:12:26 +09:00
Родитель 0eb1c4ea3a
Коммит e2ec97c4b8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7CD2805BFA3770C6
1 изменённых файлов: 31 добавлений и 1 удалений

Просмотреть файл

@ -4081,7 +4081,6 @@ rb_str_rindex(VALUE str, VALUE sub, long pos)
return str_rindex(str, sub, s, pos, enc);
}
/*
* call-seq:
* rindex(substring, offset = self.length) -> integer or nil
@ -4103,6 +4102,23 @@ rb_str_rindex(VALUE str, VALUE sub, long pos)
* 'foo'.rindex(/oo/) # => 1
* 'foo'.rindex(/ooo/) # => nil
*
* The _last_ match means starting at the possible last position, not
* the last of longest matches.
*
* 'foo'.rindex(/o+/) # => 2
* $~ #=> #<MatchData "o">
*
* To get the last longest match, needs to combine with negative
* lookbehind.
*
* 'foo'.rindex(/(?<!o)o+/) # => 1
* $~ #=> #<MatchData "oo">
*
* Or String#index with negative lookforward.
*
* 'foo'.index(/o+(?!.*o)/) # => 1
* $~ #=> #<MatchData "oo">
*
* \Integer argument +offset+, if given and non-negative, specifies the maximum starting position in the
* string to _end_ the search:
*
@ -10395,6 +10411,20 @@ rb_str_partition(VALUE str, VALUE sep)
* "hello".rpartition("l") #=> ["hel", "l", "o"]
* "hello".rpartition("x") #=> ["", "", "hello"]
* "hello".rpartition(/.l/) #=> ["he", "ll", "o"]
*
* The match from the end means starting at the possible last position, not
* the last of longest matches.
*
* "hello".rpartition(/l+/) #=> ["hel", "l", "o"]
*
* To partition at the last longest match, needs to combine with
* negative lookbehind.
*
* "hello".rpartition(/(?<!l)l+/) #=> ["he", "ll", "o"]
*
* Or String#partition with negative lookforward.
*
* "hello".partition(/l+(?!.*l)/) #=> ["he", "ll", "o"]
*/
static VALUE