string

mtch.string â str Instance Public methods Returns a frozen copy of the string passed in to match. m = /(.)(.)(\d+)(\d)/.match("THX1138.") m.string #=> "THX1138."

size

mtch.size â integer Instance Public methods Returns the number of elements in the match array. m = /(.)(.)(\d+)(\d)/.match("THX1138.") m.length #=> 5 m.size #=> 5

regexp

mtch.regexp â regexp Instance Public methods Returns the regexp. m = /a.*b/.match("abc") m.regexp #=> /a.*b/

pretty_print

pretty_print(q) Instance Public methods

pre_match

mtch.pre_match â str Instance Public methods Returns the portion of the original string before the current match. Equivalent to the special variable $`. m = /(.)(.)(\d+)(\d)/.match("THX1138.") m.pre_match #=> "T"

post_match

mtch.post_match â str Instance Public methods Returns the portion of the original string after the current match. Equivalent to the special variable $'. m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") m.post_match #=> ": The Movie"

offset

mtch.offset(n) â array Instance Public methods Returns a two-element array containing the beginning and ending offsets of the nth match. n can be a string or symbol to reference a named capture. m = /(.)(.)(\d+)(\d)/.match("THX1138.") m.offset(0) #=> [1, 7] m.offset(4) #=> [6, 7] m = /(?<foo>.)(.)(?<bar>.)/.match("hoge") p m.offset(:foo) #=> [0, 1] p m.offset(:bar) #=> [2, 3]

names

mtch.names â [name1, name2, ...] Instance Public methods Returns a list of names of captures as an array of strings. It is same as mtch.regexp.names. /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").names #=> ["foo", "bar", "baz"] m = /(?<x>.)(?<y>.)?/.match("a") #=> #<MatchData "a" x:"a" y:nil> m.names #=> ["x", "y"]

length

mtch.length â integer Instance Public methods Returns the number of elements in the match array. m = /(.)(.)(\d+)(\d)/.match("THX1138.") m.length #=> 5 m.size #=> 5

inspect

mtch.inspect â str Instance Public methods Returns a printable version of mtch. puts /.$/.match("foo").inspect #=> #<MatchData "o"> puts /(.)(.)(.)/.match("foo").inspect #=> #<MatchData "foo" 1:"f" 2:"o" 3:"o"> puts /(.)(.)?(.)/.match("fo").inspect #=> #<MatchData "fo" 1:"f" 2:nil 3:"o"> puts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").inspect #=> #<MatchData "hog" foo:"h" bar:"o" baz:"g">