るりまサーチ

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

別のキーワード

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

ライブラリ

キーワード

検索結果

<< 1 2 3 > >>

MatchData#post_match -> String (9120.0)

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

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

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

@
see MatchData#pre_match...

MatchData#pre_match -> String (9120.0)

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

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

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

@
see MatchData#post_match...

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

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

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

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

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

@
raise IndexError 正規表現中で定義されていな...
...ます。

//emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\d{1,2})月(?:(?<day>\d{1,2})日)?/ =~ "2021年1月"
p $~.byteoffset('year') # => [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#byteoffset(n) -> [Integer, Integer] | [nil, nil] (6325.0)

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

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

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

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

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

@
see MatchData#offset...

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

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

...バイトオフセットを返します。

@
param n 部分文字列を指定する数値。
@
param name 名前付きキャプチャを指定する文字列またはシンボル。

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

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

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

絞り込み条件を変える

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

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

...バイトオフセットを返します。

@
param n 部分文字列を指定する数値。
@
param name 名前付きキャプチャを指定する文字列またはシンボル。

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

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

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

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

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

...バイトオフセットを返します。

@
param n 部分文字列を指定する数値。
@
param name 名前付きキャプチャを指定する文字列またはシンボル。

@
raise IndexError 範囲外の n を指定した場合に発生します。
@
raise IndexError 正規表現中で定義...
...ist[例][ruby]{
/(c).*(いう).*(e.*)/ =~ 'abcあいうdef'
p $~ # => #<MatchData "cあいうdef" 1:"c" 2:"いう" 3:"ef">
p $~.byteend(0) # => 15
p $~.byteend(1) # => 3
p $~.byteend(2) # => 12
p $~.byteend(3) # => 15
p $~.byteend(4) # => 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 group name reference: foo (IndexError)
//}...

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

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

...バイトオフセットを返します。

@
param n 部分文字列を指定する数値。
@
param name 名前付きキャプチャを指定する文字列またはシンボル。

@
raise IndexError 範囲外の n を指定した場合に発生します。
@
raise IndexError 正規表現中で定義...
...ist[例][ruby]{
/(c).*(いう).*(e.*)/ =~ 'abcあいうdef'
p $~ # => #<MatchData "cあいうdef" 1:"c" 2:"いう" 3:"ef">
p $~.byteend(0) # => 15
p $~.byteend(1) # => 3
p $~.byteend(2) # => 12
p $~.byteend(3) # => 15
p $~.byteend(4) # => 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 group name reference: foo (IndexError)
//}...

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

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

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

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

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

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

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

@
raise IndexErr...
...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...
...# => `offset': undefined group name reference: century (IndexError)
//}

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

絞り込み条件を変える

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

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

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

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

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

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

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

@
see MatchData#begin, MatchData#end...
...の n を指定した場合に発生します。

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

MatchData#deconstruct_keys(array_of_names) -> Hash (6126.0)

引数で指定された名前の名前付きキャプチャを Hash で返します。

...

@
param array_of_names 名前付きキャプチャの名前の配列を指定します。nil の場合は全ての名前付きキャプチャを意味します。

//emlist[例][ruby]{
m = /(?<hours>\d{2}):(?<minutes>\d{2}):(?<seconds>\d{2})/.match("18:37:22")
m.deconstruct_keys([:hours, :minutes])...
...nutes => "37"}
m.deconstruct_keys(nil) # => {:hours => "18", :minutes => "37", :seconds => "22"}

# 名前付きキャプチャが定義されていなかった場合は空のハッシュを返す
m = /(\d{2}):(\d{2}):(\d{2})/.match("18:37:22")
m.deconstruct_keys(nil) # => {}
//}

@
see d:spec/patter...
...n_matching#matching_non_primitive_objects...

MatchData#named_captures -> Hash (6126.0)

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

...

@
param symbolize_names 真を指定するとハッシュのキーを文字列ではなくシンボルにします。デフォルトは偽です。

//emlist[例][ruby]{
m = /(?<a>.)(?<b>.)/.match("01")
m.named_captures # => {"a" => "0", "b" => "1"}

m = /(?<a>.)(?<b>.)?/.match("0")
m.named_capture...
...s # => {"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...
...s # => {"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#deconstruct_keys...

MatchData#named_captures(symbolize_names: false) -> Hash (6126.0)

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

...

@
param symbolize_names 真を指定するとハッシュのキーを文字列ではなくシンボルにします。デフォルトは偽です。

//emlist[例][ruby]{
m = /(?<a>.)(?<b>.)/.match("01")
m.named_captures # => {"a" => "0", "b" => "1"}

m = /(?<a>.)(?<b>.)?/.match("0")
m.named_capture...
...", "b" => nil}

m = /(?<a>.)(?<a>.)/.match("01")
m.named_captures # => {"a" => "1"}

m = /(?<a>x)|(?<a>y)/.match("x")
m.named_captures # => {"a" => "x"}

m = /(?<a>.)(?<a>.)/.match("01")
m.named_captures(symbolize_names: true) #=> {:a => "1"}
//}

@
see MatchData#captures, MatchData#deconstruct_keys...

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

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

...列全体を表します。

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

//emlist[例][ruby]{
m = /(foo)(bar)(baz)/.match("foobarbaz")
# same as m.to_a.values_at(...)
p m.values_at(0, 1, 2, 3, 4) # => ["fo...
...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] (6120.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...
...=> ["foo", "bar", nil]
//}

@
see MatchData#to_a, MatchData#named_captures, d:spec/pattern_matching#matching_non_primitive_objects...

MatchData#to_a -> [String] (6120.0)

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

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

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

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