3件ヒット
[1-3件を表示]
(0.116秒)
キーワード
-
named
_ captures (1) -
to
_ a (1)
検索結果
先頭3件
-
MatchData
# captures -> [String] (78949.0) -
$1, $2, ... を格納した配列を返します。
$1, $2, ... を格納した配列を返します。
MatchData#to_a と異なり $& を要素に含みません。
グループにマッチした部分文字列がなければ対応する要素は nil になります。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
p $~.captures # => ["foo", "bar", nil]
//}
@see MatchData#to_a, MatchData#named_captures -
Regexp
# named _ captures -> { String => [Integer] } (43267.0) -
正規表現に含まれる名前付きキャプチャ(named capture)の情報を Hash で返します。
正規表現に含まれる名前付きキャプチャ(named capture)の情報を
Hash で返します。
Hash のキーは名前付きキャプチャの名前で、値は
その名前に関連付けられたキャプチャの index のリストを返します。
//emlist[例][ruby]{
/(?<foo>.)(?<bar>.)/.named_captures
# => {"foo"=>[1], "bar"=>[2]}
/(?<foo>.)(?<foo>.)/.named_captures
# => {"foo"=>[1, 2]}
# 名前付きキャプチャを持たないときは空の Hash を返します。
/(.)(.)/... -
MatchData
# to _ a -> [String] (24628.0) -
$&, $1, $2,... を格納した配列を返します。
$&, $1, $2,... を格納した配列を返します。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
//}
@see MatchData#captures