るりまサーチ

最速Rubyリファレンスマニュアル検索!
110件ヒット [1-100件を表示] (0.111秒)

別のキーワード

  1. string []=
  2. string []
  3. string slice
  4. string slice!
  5. string gsub

ライブラリ

キーワード

検索結果

<< 1 2 > >>

MatchData#[](name) -> String | nil (121.0)

name という名前付きグループにマッチした文字列を返します。

...name という名前付きグループにマッチした文字列を返します。

@
param name 名前(シンボルか文字列)
@
raise IndexError 指定した名前が正規表現内に含まれていない場合に発生します

//emlist[例][ruby]{
/\$(?<dollars>\d+)\.(?<cents>\d+)/.match("$3...

MatchData#[](n) -> String | nil (116.0)

n 番目の部分文字列を返します。

...尾からのインデックスと見倣します(末尾の
要素が -1 番目)。n 番目の要素が存在しない時には nil を返します。

@
param n 返す部分文字列のインデックスを指定します。

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

MatchData#[](range) -> [String] (116.0)

Range オブジェクト range の範囲にある要素からなる部分配列を返します。

...Range オブジェクト range の範囲にある要素からなる部分配列を返します。

@
param range start..end 範囲式。

//emlist[例][ruby]{
/(foo)(bar)/ =~ "foobarbaz"
p $~[0..2] # => ["foobar", "foo", "bar"]
//}...

MatchData#[](start, length) -> [String] (116.0)

start 番目から length 個の要素を含む部分配列を返します。

...start 番目から length 個の要素を含む部分配列を返します。

//emlist[例][ruby]{
/(foo)(bar)/ =~ "foobarbaz"
p $~[0, 3] # => ["foobar", "foo", "bar"]
//}

@
see Array#[]...

MatchData#values_at(*index) -> [String] (115.0)

正規表現中の n 番目の括弧にマッチした部分文字列の配列を返します。

...目の括弧にマッチした部分文字列の配列を返します。

0 番目は $& のようにマッチした文字列全体を表します。

@
param index インデックスを整数またはシンボル(名前付きキャプチャの場合)で 0 個以上指定します。

//emlist[例][r...
...z", "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#[]...

絞り込み条件を変える

MatchData#captures -> [String] (110.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, d:spec/pattern_matching#matching_non_primitive_objects...

MatchData#deconstruct -> [String] (110.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, d:spec/pattern_matching#matching_non_primitive_objects...

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

MatchData#post_match -> String (109.0)

マッチした部分より後ろの文字列を返します($'と同じ)。

...マッチした部分より後ろの文字列を返します($'と同じ)。

//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.post_match # => "baz"
//}

@
see MatchData#pre_match...

MatchData#pre_match -> String (109.0)

マッチした部分より前の文字列を返します($`と同じ)。

...マッチした部分より前の文字列を返します($`と同じ)。

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

@
see MatchData#post_match...

絞り込み条件を変える

MatchData#to_a -> [String] (109.0)

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

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

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

@
see MatchData#captures...
<< 1 2 > >>