D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
MatchData
/
Filename :
cdesc-MatchData.ri
back
Copy
U:RDoc::NormalClass[iI"MatchData:ET@I"Object;To:RDoc::Markup::Document:@parts[o;;[o:RDoc::Markup::Paragraph;[I"DMatchData encapsulates the result of matching a Regexp against ;TI"Gstring. It is returned by Regexp#match and String#match, and also ;TI"?stored in a global variable returned by Regexp.last_match.;To:RDoc::Markup::BlankLine o; ;[I"Usage:;T@o:RDoc::Markup::Verbatim;[I"@url = 'https://docs.ruby-lang.org/en/2.5.0/MatchData.html' ;TI"Am = url.match(/(\d\.?)+/) # => #<MatchData "2.5.0" 1:"0"> ;TI"[m.string # => "https://docs.ruby-lang.org/en/2.5.0/MatchData.html" ;TI"1m.regexp # => /(\d\.?)+/ ;TI"!# entire matched substring: ;TI".m[0] # => "2.5.0" ;TI" ;TI"%# Working with unnamed captures ;TI"/m = url.match(%r{([^/]+)/([^/]+)\.html$}) ;TI"=m.captures # => ["2.5.0", "MatchData"] ;TI".m[1] # => "2.5.0" ;TI"=m.values_at(1, 2) # => ["2.5.0", "MatchData"] ;TI" ;TI"## Working with named captures ;TI"Bm = url.match(%r{(?<version>[^/]+)/(?<module>[^/]+)\.html$}) ;TI"=m.captures # => ["2.5.0", "MatchData"] ;TI"Rm.named_captures # => {"version"=>"2.5.0", "module"=>"MatchData"} ;TI".m[:version] # => "2.5.0" ;TI"$m.values_at(:version, :module) ;TI"= # => ["2.5.0", "MatchData"] ;TI"*# Numerical indexes are working, too ;TI".m[1] # => "2.5.0" ;TI"=m.values_at(1, 2) # => ["2.5.0", "MatchData"] ;T:@format0S:RDoc::Markup::Heading: leveli: textI"!Global variables equivalence;T@o; ;[I"FParts of last MatchData (returned by Regexp.last_match) are also ;TI"!aliased as global variables:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o; ;[I"*<code>$~</code> is Regexp.last_match;;To;;0;[o; ;[I"<<code>$&</code> is Regexp.last_match<code>[ 0 ]</code>;;To;;0;[o; ;[I"5<code>$1</code>, <code>$2</code>, and so on are ;TI">Regexp.last_match<code>[ i ]</code> (captures by number);;To;;0;[o; ;[I"A<code>$`</code> is Regexp.last_match<code>.pre_match</code>;;To;;0;[o; ;[I"B<code>$'</code> is Regexp.last_match<code>.post_match</code>;;To;;0;[o; ;[I"P<code>$+</code> is Regexp.last_match<code>[ -1 ]</code> (the last capture).;T@o; ;[I"ISee also "Special global variables" section in Regexp documentation.;T: @fileI" re.c;T:0@omit_headings_from_table_of_contents_below0;0;0[ [ [ [[I" class;T[[:public[ [:protected[ [:private[ [I" instance;T[[;[ [I"==;TI" re.c;T[I"[];T@n[I" begin;T@n[I"bytebegin;T@n[I"byteend;T@n[I"byteoffset;T@n[I" captures;T@n[I"deconstruct;T@n[I"deconstruct_keys;T@n[I"end;T@n[I" eql?;T@n[I" hash;T@n[I"inspect;T@n[I"length;T@n[I" match;T@n[I"match_length;T@n[I"named_captures;T@n[I" names;T@n[I"offset;T@n[I"post_match;T@n[I"pre_match;T@n[I"regexp;T@n[I" size;T@n[I"string;T@n[I" to_a;T@n[I" to_s;T@n[I"values_at;T@n[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ;0;0[I"lib/pp.rb;T@Y@YcRDoc::TopLevel