Class: MatchData
Overview
MatchData is the class of the object returned by String#match
, Regexp#match
, and Regexp#last_match
. It encapsulates all the results of a pattern match.
Instance Method Summary collapse
- #[](*args) ⇒ Object
-
#begin(n) ⇒ Object
FIX: Incomplete.
-
#captures ⇒ Object
call-seq: mtch.captures -> array.
-
#end(n) ⇒ Object
FIX: Incomplete.
-
#initialize ⇒ MatchData
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#length ⇒ Object
call-seq: mtch.length -> integer mtch.size -> integer.
-
#offset(n) ⇒ Object
FIX: Incomplete.
-
#post_match ⇒ Object
call-seq: mtch.post_match -> string.
-
#pre_match ⇒ Object
call-seq: mtch.pre_match -> string.
-
#select ⇒ Object
FIX: Incomplete.
-
#size ⇒ Object
call-seq: mtch.length -> integer mtch.size -> integer.
-
#string ⇒ Object
call-seq: mtch.string -> string.
-
#to_a ⇒ Object
call-seq: mtch.to_a -> array.
-
#to_s ⇒ Object
call-seq: mtch.to_s -> string.
-
#values_at ⇒ Object
FIX: Incomplete.
Constructor Details
#initialize ⇒ MatchData
:nodoc:
3865 3866 3867 |
# File 'lib/source/ruby.rb', line 3865 def initialize # :nodoc: `this._captures=[]` end |
Instance Method Details
#[](*args) ⇒ Object
call-seq:
mtch[i] -> object
mtch[start, length] -> array
mtch[range] -> array
Match Reference – MatchData acts as an array, and may be accessed using the normal array indexing techniques. mtch[0]
returns the entire matched string, while mtch[1]
, mtch[2]
, and so on return the values of the matched backreferences (portions of the pattern between parentheses).
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m[0] #=> "HX1138"
m[1, 2] #=> ["H", "X"]
m[1..3] #=> ["H", "X", "113"]
m[-3, 2] #=> ["X", "113"]
3887 3888 3889 |
# File 'lib/source/ruby.rb', line 3887 def [](*args) `c$Array.prototype.m$_brac.apply(this._captures,args)` end |
#begin(n) ⇒ Object
FIX: Incomplete
3892 3893 |
# File 'lib/source/ruby.rb', line 3892 def begin(n) end |
#captures ⇒ Object
call-seq:
mtch.captures -> array
Returns the array of captures.
m = /(.)(.)(\d+)(\d)/.match("THX1138.").captures
m[0] #=> "H"
m[1] #=> "X"
m[2] #=> "113"
m[3] #=> "8"
3907 3908 3909 |
# File 'lib/source/ruby.rb', line 3907 def captures `this._captures.slice(1)` end |
#inspect ⇒ Object
:nodoc:
3929 3930 3931 |
# File 'lib/source/ruby.rb', line 3929 def inspect # :nodoc: `c$Object.prototype.m$toS.apply(this)` end |
#length ⇒ Object
call-seq:
mtch.length -> integer
mtch.size -> integer
Returns the number of elements in the match array.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.length #=> 5
3925 3926 3927 |
# File 'lib/source/ruby.rb', line 3925 def length `this._captures.length` end |
#offset(n) ⇒ Object
FIX: Incomplete
3934 3935 |
# File 'lib/source/ruby.rb', line 3934 def offset(n) end |
#post_match ⇒ Object
call-seq:
mtch.post_match -> string
Returns the portion of the original string after the current match.
m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
m.post_match #=> ": The Movie"
3946 3947 3948 |
# File 'lib/source/ruby.rb', line 3946 def post_match `this._post` end |
#pre_match ⇒ Object
call-seq:
mtch.pre_match -> string
Returns the portion of the original string before the current match.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.pre_match #=> "T"
3959 3960 3961 |
# File 'lib/source/ruby.rb', line 3959 def pre_match `this._pre` end |
#size ⇒ Object
call-seq:
mtch.length -> integer
mtch.size -> integer
Returns the number of elements in the match array.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.size #=> 5
3977 3978 3979 |
# File 'lib/source/ruby.rb', line 3977 def size `this._captures.length` end |
#string ⇒ Object
call-seq:
mtch.string -> string
Returns a copy of the string that was matched against a pattern to produce mtch.
m1 = /(.)(.)(\d+)(\d)/.match("THX1138.")
m2 = "THX1138.".match(/(.)(.)(\d+)(\d)/)
m1.string #=> "THX1138."
m2.string #=> "THX1138."
3993 3994 3995 |
# File 'lib/source/ruby.rb', line 3993 def string `$q(this._string)` end |
#to_a ⇒ Object
call-seq:
mtch.to_a -> array
Returns the MatchData’s internal array.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.to_a #=> ["HX1138", "H", "X", "113", "8"]
4006 4007 4008 |
# File 'lib/source/ruby.rb', line 4006 def to_a `this._captures` end |
#to_s ⇒ Object
call-seq:
mtch.to_s -> string
Returns the entire matched string.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.to_s #=> "HX1138"
4019 4020 4021 |
# File 'lib/source/ruby.rb', line 4019 def to_s `this._captures[0]` end |
#values_at ⇒ Object
FIX: Incomplete
4024 4025 |
# File 'lib/source/ruby.rb', line 4024 def values_at end |