るりまサーチ

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

別のキーワード

  1. _builtin to_r
  2. open3 pipeline_r
  3. matrix elements_to_r
  4. fileutils rm_r
  5. fileutils cp_r

ライブラリ

キーワード

検索結果

MatchData#begin(n) -> Integer | nil (24538.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(n) -> [Integer, Integer] | [nil, nil] (415.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...
...指定した場合に発生します。

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

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

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

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

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

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

MatchData#end(n) -> Integer | nil (307.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...