15件ヒット
[1-15件を表示]
(0.142秒)
別のキーワード
ライブラリ
- ビルトイン (15)
キーワード
- byteoffset (4)
-
named
_ captures (11)
検索結果
先頭3件
-
MatchData
# byteoffset(name) -> [Integer , Integer] | [nil , nil] (6138.0) -
name という名前付きグループに対応する部分文字列のバイト単位のオフセットの 配列 [start, end] を返します。
...@param name 名前(シンボルか文字列)
@raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。
//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] (6108.0) -
n 番目の部分文字列のバイト単位のオフセットの 配列 [start, end] を返します。
...のオフセットの
配列 [start, end] を返します。
n番目の部分文字列がマッチしていなければ [nil, nil] を返します。
@param n 部分文字列を指定する数値
@raise IndexError 範囲外の n を指定した場合に発生します。
@see MatchData#offset... -
MatchData
# named _ captures -> Hash (6108.0) -
名前付きキャプチャをHashで返します。
...st[例][ruby]{
m = /(?<a>.)(?<b>.)/.match("01")
m.named_captures # => {"a" => "0", "b" => "1"}
m = /(?<a>.)(?<b>.)?/.match("0")
m.named_captures # => {"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...