Return the primary match string. This is equivalent to +md[0]+.
md = /123/.match "123456" md.match #=> "123"
CREDIT: Martin DeMello
# File lib/core/facets/matchdata/match.rb, line 10
10: def match(index=0)
11: self[index]
12: end
Returns [ pre_match, matchtree, post_match ]. (see matchtree)
md = /(bb)(cc(dd))(ee)/.match "XXaabbccddeeffXX" md.to_a #=> ["XXaabbccddeeffXX", "bb", "ccdd", "dd", "ee"] md.matchset #=> ["XXaa", [["bb"], ["cc", ["dd"]], "ee"], "ffXX"]
CREDIT: Trans
# File lib/core/facets/matchdata/matchset.rb, line 11
11: def matchset
12: [pre_match, matchtree, post_match]
13: end
An alternate to # which returns the matches in order corresponding with the regular expression.
md = /(bb)(cc(dd))(ee)/.match "XXaabbccddeeffXX" md.to_a #=> ["XXaabbccddeeffXX", "bb", "ccdd", "dd", "ee"] md.matchtree #=> [["bb"], ["cc", ["dd"]], "ee"]
CREDIT: Trans
# File lib/core/facets/matchdata/matchset.rb, line 24
24: def matchtree(index=0)
25: ret=[]
26: b, e=self.begin(index), self.end(index)
27: while (index+=1)<=length
28: if index==length || (bi=self.begin(index))>=e
29: # we are finished, if something is left, then add it
30: ret << string[b, e-b] if e>b
31: break
32: else
33: if bi>=b
34: ret << string[b, bi-b] if bi>b
35: ret << matchtree(index)
36: b=self.end(index)
37: end
38: end
39: end
40: return ret
41: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.