diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-09 07:35:54 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-09 07:35:54 +0000 |
commit | 7a7c26be7328099b4b2ba57ba9547e20080e071f (patch) | |
tree | 6c84ad683c0217a51f2ae66a7b9c1a6040bcecad | |
parent | 18d8fbac5484411bc7194c408edf0a3e17ea640d (diff) |
document named capture of MatchData#{offset,begin,end,inspect}.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | re.c | 23 | ||||
-rw-r--r-- | test/ruby/test_regexp.rb | 1 |
2 files changed, 20 insertions, 4 deletions
@@ -666,6 +666,11 @@ match_backref_number(VALUE match, VALUE backref) * 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] + * */ static VALUE @@ -694,6 +699,10 @@ match_offset(VALUE match, VALUE n) * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m.begin(0) #=> 1 * m.begin(2) #=> 2 + * + * m = /(?<foo>.)(.)(?<bar>.)/.match("hoge") + * p m.begin(:foo) #=> 0 + * p m.begin(:bar) #=> 2 */ static VALUE @@ -721,6 +730,10 @@ match_begin(VALUE match, VALUE n) * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m.end(0) #=> 7 * m.end(2) #=> 3 + * + * m = /(?<foo>.)(.)(?<bar>.)/.match("hoge") + * p m.end(:foo) #=> 1 + * p m.end(:bar) #=> 3 */ static VALUE @@ -1284,11 +1297,15 @@ match_inspect_name_iter(const OnigUChar *name, const OnigUChar *name_end, * * Returns a printable version of <i>mtch</i>. * - * /.$/ =~ "foo"; puts $~.inspect + * puts /.$/.match("foo").inspect * #=> #<MatchData "o"> * - * /(.)(.)(.)/ =~ "foo"; puts $~.inspect - * #=> #<MatchData "foo" "f" "o" "o"> + * puts /(.)(.)(.)/.match("foo").inspect + * #=> #<MatchData "foo" 1:"f" 2:"o" 3:"o"> + * + * puts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").inspect + * #=> #<MatchData "hog" foo:"h" bar:"o" baz:"g"> + * */ static VALUE diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index f052b946c0..09022629d5 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -57,7 +57,6 @@ class TestRegexp < Test::Unit::TestCase assert_equal(5, m.begin(:foo)) assert_equal(8, m.end(:foo)) assert_equal([5,8], m.offset(:foo)) - #assert_equal(["amp"], m.values_at(:foo)) assert_equal("aaa [amp] yyy", "aaa & yyy".sub(/&(?<foo>.*?);/, '[\k<foo>]')) |