るりまサーチ

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

別のキーワード

  1. matchdata []
  2. matchdata offset
  3. _builtin matchdata
  4. matchdata names

ライブラリ

キーワード

検索結果

MatchData#captures -> [String] (27132.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 (15138.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] (9013.0)

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

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

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

@see MatchData#captures...