るりまサーチ

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

別のキーワード

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

キーワード

検索結果

MatchData#captures -> [String] (18116.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 (6134.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...

MatchData#to_a -> [String] (9.0)

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

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

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
//}

@see MatchData#captures...