るりまサーチ

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

別のキーワード

  1. _builtin to_i
  2. fiddle to_i
  3. matrix elements_to_i
  4. csv to_i
  5. matrix i

ライブラリ

キーワード

検索結果

<< 1 2 3 > >>

MatchData#begin(n) -> Integer | nil (6201.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#inspect -> String (6201.0)

self の内容を人間に読みやすい文字列にして返します。

...

//emlist[例][ruby]{
puts /.$/.match("foo").inspect
# => #<MatchData "o">

puts /(.)(.)(.)/.match("foo").inspect
# => #<MatchData "foo" 1:"f" 2:"o" 3:"o">

puts /(.)(.)?(.)/.match("fo").inspect
# => #<MatchData "fo" 1:"f" 2:nil 3:"o">

puts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").inspect
#...

MatchData#string -> String (6201.0)

マッチ対象になった文字列の複製を返します。

...マッチ対象になった文字列の複製を返します。

返す文字列はフリーズ(Object#freeze)されています。

//emlist[例][ruby]{
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.string # => "THX1138."
//}...

MatchData#size -> Integer (3101.0)

部分文字列の数を返します(self.to_a.size と同じです)。

...部分文字列の数を返します(self.to_a.size と同じです)。

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

MatchData#byteoffset(n) -> [Integer, Integer] | [nil, nil] (201.0)

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

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

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

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

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

@see MatchData#offset...

絞り込み条件を変える

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

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

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

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

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

//emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\d{1,2})月(?...
...') # => [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#offset(n) -> [Integer, Integer] | [nil, nil] (201.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#offset(name) -> [Integer, Integer] | [nil, nil] (201.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#values_at(*index) -> [String] (201.0)

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

...m 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) # => ["foobarbaz", "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#[](n) -> String | nil (101.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#[](name) -> String | nil (101.0)

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

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

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