るりまサーチ

最速Rubyリファレンスマニュアル検索!
169件ヒット [1-100件を表示] (0.111秒)
トップページ > クエリ:Ruby[x] > クエリ:ruby[x] > 種類:インスタンスメソッド[x] > クエリ:i[x] > クエリ:@[x] > クラス:MatchData[x]

別のキーワード

  1. fiddle ruby_free
  2. rbconfig ruby
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

キーワード

検索結果

<< 1 2 > >>

MatchData#bytebegin(n) -> Integer | nil (6286.0)

n 番目の部分文字列先頭のバイトオフセットを返します。

...がマッチしていなければ nilを返します。

引数に文字列またはシンボルを渡した場合は、対応する名前付きキャプチャの先頭のバイトオフセットを返します。

@
param n 部分文字列を指定する数値。
@
param name 名前付きキャプチ...
...ル。

@
raise IndexError 範囲外の n を指定した場合に発生します。
@
raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。

//emlist[例][ruby]{
/(c).*(いう).*(e.*)/ =~ 'abcあいうdef'
p $~ # => #<MatchData "cあ...
...egin(0) # => 2
p $~.bytebegin(1) # => 2
p $~.bytebegin(2) # => 6
p $~.bytebegin(3) # => 13
p $~.bytebegin(4) # => index 4 out of matches (IndexError)
//}

//emlist[シンボルを指定する例][ruby]{
/(?<key>\S+):\s*(?<value>\S+)/ =~ "name: ruby"
$~ # => #<MatchData "name: ruby"...

MatchData#bytebegin(name) -> Integer | nil (6286.0)

n 番目の部分文字列先頭のバイトオフセットを返します。

...がマッチしていなければ nilを返します。

引数に文字列またはシンボルを渡した場合は、対応する名前付きキャプチャの先頭のバイトオフセットを返します。

@
param n 部分文字列を指定する数値。
@
param name 名前付きキャプチ...
...ル。

@
raise IndexError 範囲外の n を指定した場合に発生します。
@
raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。

//emlist[例][ruby]{
/(c).*(いう).*(e.*)/ =~ 'abcあいうdef'
p $~ # => #<MatchData "cあ...
...egin(0) # => 2
p $~.bytebegin(1) # => 2
p $~.bytebegin(2) # => 6
p $~.bytebegin(3) # => 13
p $~.bytebegin(4) # => index 4 out of matches (IndexError)
//}

//emlist[シンボルを指定する例][ruby]{
/(?<key>\S+):\s*(?<value>\S+)/ =~ "name: ruby"
$~ # => #<MatchData "name: ruby"...

MatchData#begin(n) -> Integer | nil (6232.0)

n 番目の部分文字列先頭のオフセットを返します。

...nilを返します。

@
param n 部分文字列を指定する数値。

@
raise IndexError 範囲外の n を指定した場合に発生します。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.begin(0) # => 0
p $~.begin(1) # => 0
p $~.begin(2) # => 3
p $~.begin(3) # => nil...
...p $~.begin(4) # => `begin': index 4 out of matches (IndexError)
//}

@
see MatchData#end...

MatchData#offset(name) -> [Integer, Integer] | [nil, nil] (249.0)

name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返 します。

...nd] を返
します。

//emlist[例][ruby]{
[ self.begin(name), self.end(name) ]
//}

と同じです。nameの名前付きグループにマッチした部分文字列がなければ
[nil, nil] を返します。

@
param name 名前(シンボルか文字列)

@
raise IndexError 正規表現中で...
...す。

//emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\d{1,2})月(?:(?<day>\d{1,2})日)?/ =~ "2021年1月"
p $~.offset('year') # => [0, 4]
p $~.offset(:year) # => [0, 4]
p $~.offset('month') # => [5, 6]
p $~.offset(:month) # => [5, 6]
p $~.offset('day') # => [nil, nil]
p $~.offset(...
...'century') # => `offset': undefined group name reference: century (IndexError)
//}

@
see MatchData#begin, MatchData#end...
...'century') # => `offset': undefined group name reference: century (IndexError)
//}

@
see MatchData#begin, MatchData#end, MatchData#offset...

MatchData#offset(n) -> [Integer, Integer] | [nil, nil] (239.0)

n 番目の部分文字列のオフセットの配列 [start, end] を返 します。

...list[例][ruby]{
[ self.begin(n), self.end(n) ]
//}

と同じです。n番目の部分文字列がマッチしていなければ
[nil, nil] を返します。

@
param n 部分文字列を指定する数値

@
raise IndexError 範囲外の n を指定した場合に発生します。

@
see MatchData#...
...begin, MatchData#end...
...begin, MatchData#end, MatchData#offset...

絞り込み条件を変える

MatchData#byteoffset(name) -> [Integer, Integer] | [nil, nil] (235.0)

name という名前付きグループに対応する部分文字列のバイト単位のオフセットの 配列 [start, end] を返します。

...マッチした部分文字列がなければ
[nil, nil] を返します。

@
param name 名前(シンボルか文字列)

@
raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。

//emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\d{1,2})月(?:(?<da...
...# => [0, 4]
p $~.byteoffset(:year) # => [0, 4]
p $~.byteoffset('month') # => [7, 8]
p $~.byteoffset(:month) # => [7, 8]
p $~.byteoffset('day') # => [nil, nil]
p $~.byteoffset('century') # => `offset': undefined group name reference: century (IndexError)
//}

@
see MatchData#offset...
...) # => [0, 4]
p $~.byteoffset(:year) # => [0, 4]
p $~.byteoffset('month') # => [7, 8]
p $~.byteoffset(:month) # => [7, 8]
p $~.byteoffset('day') # => [nil, nil]
p $~.byteoffset('century') # => `offset': undefined group name reference: century (IndexError)
//}

@
see MatchData#offset...

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

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

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

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

//emlist[例][ruby]{
m = /(foo)(bar)(baz)/.match("foobarbaz")
# same as m.to_a.values_at(.....
...rbaz", "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#byteoffset(n) -> [Integer, Integer] | [nil, nil] (225.0)

n 番目の部分文字列のバイト単位のオフセットの 配列 [start, end] を返します。

...のオフセットの
配列 [start, end] を返します。

n番目の部分文字列がマッチしていなければ [nil, nil] を返します。

@
param n 部分文字列を指定する数値

@
raise IndexError 範囲外の n を指定した場合に発生します。

@
see MatchData#offset...

MatchData#byteend(n) -> Integer | nil (186.0)

n 番目の部分文字列終端のバイトオフセットを返します。

...がマッチしていなければ nilを返します。

引数に文字列またはシンボルを渡した場合は、対応する名前付きキャプチャの終端のバイトオフセットを返します。

@
param n 部分文字列を指定する数値。
@
param name 名前付きキャプチ...
...ル。

@
raise IndexError 範囲外の n を指定した場合に発生します。
@
raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。

//emlist[例][ruby]{
/(c).*(いう).*(e.*)/ =~ 'abcあいうdef'
p $~ # => #<MatchData "cあい...
...=> index 4 out of matches (IndexError)
//}

//emlist[シンボルを指定する例][ruby]{
/(?<key>\S+):\s*(?<value>\S+)/ =~ "name: ruby"
$~ # => #<MatchData "name: ruby" key:"name" value:"ruby">
$~.byteend(:key) # => 4
$~.byteend(:value) # => 10
$~.byteend(:foo) # => undefined...

MatchData#byteend(name) -> Integer | nil (186.0)

n 番目の部分文字列終端のバイトオフセットを返します。

...がマッチしていなければ nilを返します。

引数に文字列またはシンボルを渡した場合は、対応する名前付きキャプチャの終端のバイトオフセットを返します。

@
param n 部分文字列を指定する数値。
@
param name 名前付きキャプチ...
...ル。

@
raise IndexError 範囲外の n を指定した場合に発生します。
@
raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。

//emlist[例][ruby]{
/(c).*(いう).*(e.*)/ =~ 'abcあいうdef'
p $~ # => #<MatchData "cあい...
...=> index 4 out of matches (IndexError)
//}

//emlist[シンボルを指定する例][ruby]{
/(?<key>\S+):\s*(?<value>\S+)/ =~ "name: ruby"
$~ # => #<MatchData "name: ruby" key:"name" value:"ruby">
$~.byteend(:key) # => 4
$~.byteend(:value) # => 10
$~.byteend(:foo) # => undefined...

絞り込み条件を変える

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

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

...

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

//emlist[例][ruby]{
/\$(?<dollars>\d+)\.(?<cents>\d+)/.match("$3.67")[:cents] # => "67"
/(?<alpha>[a-zA-Z]+)|(?<num>\d+)/.match("aZq")[:num] # => ni...

MatchData#end(n) -> Integer | nil (132.0)

n 番目の部分文字列終端のオフセットを返します。

...ば nil を返します。

@
param n 部分文字列を指定する数値。

@
raise IndexError 範囲外の n を指定した場合に発生します。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.end(0) # => 6
p $~.end(1) # => 3
p $~.end(2) # => 6
p $~.end(3) # => nil
p $~...
....end(4) # => `end': index 4 out of matches (IndexError)
//}

@
see MatchData#begin...

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

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

...)。n 番目の要素が存在しない時には nil を返します。

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

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
p $~[0] # => "foobar"
p $~[1] #...
...=> "foo"
p $~[2] # => "bar"
p $~[3] # => nil (マッチしていない)
p $~[4] # => nil (範囲外)
p $~[-2] # => "bar"
//}...

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

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

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

@
param range start..end 範囲式。

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