[DOC] Tweaks for String#=~ (#13325)
This commit is contained in:
parent
c3eb406876
commit
4fc5047af8
Notes:
git
2025-05-15 15:19:03 +00:00
Merged-By: peterzhu2118 <peter@peterzhu.ca>
29
string.c
29
string.c
@ -5332,30 +5332,33 @@ rb_str_byterindex_m(int argc, VALUE *argv, VALUE str)
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* string =~ regexp -> integer or nil
|
||||
* string =~ object -> integer or nil
|
||||
* self =~ object -> integer or nil
|
||||
*
|
||||
* Returns the Integer index of the first substring that matches
|
||||
* the given +regexp+, or +nil+ if no match found:
|
||||
* When +object+ is a Regexp, returns the index of the first substring in +self+
|
||||
* matched by +object+,
|
||||
* or +nil+ if no match is found;
|
||||
* updates {Regexp-related global variables}[rdoc-ref:Regexp@Global+Variables]:
|
||||
*
|
||||
* 'foo' =~ /f/ # => 0
|
||||
* $~ # => #<MatchData "f">
|
||||
* 'foo' =~ /o/ # => 1
|
||||
* $~ # => #<MatchData "o">
|
||||
* 'foo' =~ /x/ # => nil
|
||||
*
|
||||
* Note: also updates Regexp@Global+Variables.
|
||||
*
|
||||
* If the given +object+ is not a Regexp, returns the value
|
||||
* returned by <tt>object =~ self</tt>.
|
||||
* $~ # => nil
|
||||
*
|
||||
* Note that <tt>string =~ regexp</tt> is different from <tt>regexp =~ string</tt>
|
||||
* (see Regexp#=~):
|
||||
*
|
||||
* number = nil
|
||||
* "no. 9" =~ /(?<number>\d+)/
|
||||
* number # => nil (not assigned)
|
||||
* /(?<number>\d+)/ =~ "no. 9"
|
||||
* number #=> "9"
|
||||
* 'no. 9' =~ /(?<number>\d+)/ # => 4
|
||||
* number # => nil # Not assigned.
|
||||
* /(?<number>\d+)/ =~ 'no. 9' # => 4
|
||||
* number # => "9" # Assigned.
|
||||
*
|
||||
* If +object+ is not a Regexp, returns the value
|
||||
* returned by <tt>object =~ self</tt>.
|
||||
*
|
||||
* Related: see {Querying}[rdoc-ref:String@Querying].
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
Loading…
x
Reference in New Issue
Block a user