In Files

Parent

Files

Class/Module Index [+]

Quicksearch

MatchData

Public Instance Methods

mtch[i] => obj click to toggle source
mtch[start, length] => array
mtch[range] => array
mtch[symbol] => obj

MatchData acts as an array, and may be accessed using the normal array indexing techniques. mtch is equivalent to the special variable $&, and returns the entire matched string. mtch, mtch, and so on return the values of the matched backreferences (portions of the pattern between parentheses).

m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
m[0]       #=> "HX1138"
m[1, 2]    #=> ["H", "X"]
m[1..3]    #=> ["H", "X", "113"]
m[-3, 2]   #=> ["X", "113"]

If a symbol is used as index, the corresponding named group is returned, or nil if such a group does not exist.

m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
m[:begin]  #=> "THX"
m[:moddle]  #=> "1"
m[:end]  #=> "138"
# File lib/oniguruma.rb, line 359
def [](*idx)
   if idx[0].is_a?(Symbol) 
      k = to_index( idx[0] )
      k && old_aref(k)
    else
      old_aref(*idx)
    end
end
Also aliased as: old_aref
begin(n) => integer click to toggle source
begin => integer
begin(symbol) => integer

Returns the offset of the start of the nth element of the match array in the string.

m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
m.begin(0)   #=> 1
m.begin(2)   #=> 2

If no arguments are given, the index of the first matching character is returned.

m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
m.begin      #=> 1

If the argument is a symbol, then the beginning of the corresponding named group is returned, or nil if the group does not exist.

m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
m.begin(:middle) #=> 3
# File lib/oniguruma.rb, line 395
def begin(*idx)
   if idx[0].is_a?(Symbol) 
      k = to_index( idx[0] )
      k && old_begin(k)
   elsif idx.empty?
      old_begin( 0 )
   else
      old_begin(*idx)
   end
end
Also aliased as: old_begin
end(n) => integer click to toggle source

Returns the offset of the character immediately following the end of the nth element of the match array in the string.

m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
m.end(0)   #=> 7
m.end(2)   #=> 3

If no arguments are given, the index of the last matching character is returned.

m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
m.last      #=> 7

If the argument is a symbol, then the beginning of the corresponding named group is returned, or nil if the group does not exist.

m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
m.end(:middle) #=> 4
# File lib/oniguruma.rb, line 431
def end(*idx)
   if idx[0].is_a?(Symbol) 
      k = to_index( idx[0] )
      k && old_end(k)
   elsif idx.empty?
      old_end( 0 )
   else
      old_end(*idx)
   end
end
Also aliased as: old_end
offset(n) => array click to toggle source
offset => array
offset(symbol) => array

Returns a two-element array containing the beginning and ending offsets of the nth match.

m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
m.offset(0)   #=> [1, 7]
m.offset(4)   #=> [6, 7]

If no arguments are given, the offsets of the entire sequence are returned.

m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
m.offset      #=> [1, 7]

If the argument is a symbol, then the offsets of the corresponding named group are returned, or nil if the group does not exist.

m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
m.end(:middle) #=> [3, 4]
# File lib/oniguruma.rb, line 469
def offset(*idx)
   if idx[0].is_a?(Symbol) 
      k = to_index( idx[0] )
      k && old_offset(k)
   elsif idx.empty?
      old_offset( 0 )
   else
      old_offset(*idx)
   end
end
Also aliased as: old_offset
old_aref(*idx) click to toggle source
Alias for: []
old_begin(*idx) click to toggle source
Alias for: begin
old_end(*idx) click to toggle source
Alias for: end
old_offset(*idx) click to toggle source
Alias for: offset
to_index[symbol] => int or nil click to toggle source

Returns the group index for the corresponding named group, or nil if the group does not exist.

m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
m.to_index[:begin]    #=> 1
m.to_index[:unknown]  #=> nil
# File lib/oniguruma.rb, line 327
def to_index symbol
   @named_captures && @named_captures[symbol]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.