mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) e2ec97c4b8
: [Backport #18415]
[DOC] How to get the longest last match [Bug #18415] --- string.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
This commit is contained in:
parent
3ce60f44b8
commit
4b1cee1431
2 changed files with 32 additions and 2 deletions
32
string.c
32
string.c
|
@ -3846,7 +3846,6 @@ rb_str_rindex(VALUE str, VALUE sub, long pos)
|
|||
return str_rindex(str, sub, s, pos, enc);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* string.rindex(substring, offset = self.length) -> integer or nil
|
||||
|
@ -3866,6 +3865,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:
|
||||
* 'foo'.rindex('o', 0) # => nil
|
||||
|
@ -10101,6 +10117,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
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||
#define RUBY_VERSION_TEENY 4
|
||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||
#define RUBY_PATCHLEVEL 183
|
||||
#define RUBY_PATCHLEVEL 184
|
||||
|
||||
#define RUBY_RELEASE_YEAR 2022
|
||||
#define RUBY_RELEASE_MONTH 3
|
||||
|
|
Loading…
Add table
Reference in a new issue