るりまサーチ

最速Rubyリファレンスマニュアル検索!
33件ヒット [1-33件を表示] (0.046秒)
トップページ > ライブラリ:ビルトイン[x] > クエリ:captures[x] > クエリ:named_captures[x]

別のキーワード

  1. _builtin named_captures
  2. matchdata named_captures
  3. regexp named_captures
  4. matchdata captures
  5. _builtin captures

クラス

検索結果

MatchData#named_captures -> Hash (24258.0)

名前付きキャプチャをHashで返します。

...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...

Regexp#named_captures -> { String => [Integer] } (24240.0)

正規表現に含まれる名前付きキャプチャ(named capture)の情報を Hash で返します。

...のリストを返します。

//emlist[例][ruby]{
/(?<foo>.)(?<bar>.)/.named_captures
# => {"foo"=>[1], "bar"=>[2]}

/(?<foo>.)(?<foo>.)/.named_captures
# => {"foo"=>[1, 2]}

# 名前付きキャプチャを持たないときは空の Hash を返します。
/(.)(.)/.named_captures
# => {}
//}...

MatchData#captures -> [String] (18121.0)

$1, $2, ... を格納した配列を返します。

...ープにマッチした部分文字列がなければ対応する要素は 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...