33件ヒット
[1-33件を表示]
(0.087秒)
ライブラリ
- ビルトイン (33)
キーワード
- captures (11)
-
named
_ captures (11) -
values
_ at (11)
検索結果
先頭3件
-
MatchData
# captures -> [String] (6102.0) -
$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... -
MatchData
# named _ captures -> Hash (6102.0) -
名前付きキャプチャをHashで返します。
...st[例][ruby]{
m = /(?<a>.)(?<b>.)/.match("01")
m.named_captures # => {"a" => "0", "b" => "1"}
m = /(?<a>.)(?<b>.)?/.match("0")
m.named_captures # => {"a" => "0", "b" => nil}
m = /(?<a>.)(?<a>.)/.match("01")
m.named_captures # => {"a" => "1"}
m = /(?<a>x)|(?<a>y)/.match("x")
m.named_captures # =>......{"a" => "x"}
//}
@see MatchData#captures... -
MatchData
# values _ at(*index) -> [String] (6102.0) -
正規表現中の n 番目の括弧にマッチした部分文字列の配列を返します。
...チャの場合)で 0 個以上指定します。
//emlist[例][ruby]{
m = /(foo)(bar)(baz)/.match("foobarbaz")
# same as m.to_a.values_at(...)
p m.values_at(0, 1, 2, 3, 4) # => ["foobarbaz", "foo", "bar", "baz", nil]
p m.values_at(-1, -2, -3, -4, -5) # => ["baz", "bar", "foo", nil, nil]
m =....../(?<a>\d+) *(?<op>[+\-*\/]) *(?<b>\d+)/.match("1 + 2")
m.to_a # => ["1 + 2", "1", "+", "2"]
m.values_at(:a, :b, :op) # => ["1", "2", "+"]
//}
@see Array#values_at, Array#[]...