зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
18d8fbac54
Коммит
7a7c26be73
23
re.c
23
re.c
|
@ -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
|
||||
|
|
|
@ -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>]'))
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче