@@ -253,6 +253,78 @@ p $~.byteoffset('century') # => `offset': undefined group name reference: centur
253
253
254
254
@see [[m:MatchData#offset]]
255
255
#@end
256
+
257
+ #@since 3.4
258
+ --- bytebegin(n) -> Integer
259
+ --- bytebegin(name) -> Integer
260
+
261
+ n 番目の部分文字列先頭のバイトオフセットを返します。
262
+
263
+ 0 はマッチ全体を意味します。
264
+ n 番目の部分文字列がマッチしていなければ nilを返します。
265
+
266
+ 引数に文字列またはシンボルを渡した場合は、対応する名前付きキャプチャの先頭のバイトオフセットを返します。
267
+
268
+ @param n 部分文字列を指定する数値。
269
+ @param name 名前付きキャプチャを指定する文字列またはシンボル。
270
+
271
+ @raise IndexError 範囲外の n を指定した場合に発生します。
272
+ @raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。
273
+
274
+ #@samplecode 例
275
+ /(c).*(いう).*(e.*)/ =~ 'abcあいうdef'
276
+ p $~ # => #<MatchData "cあいうdef" 1:"c" 2:"いう" 3:"ef">
277
+ p $~.bytebegin(0) # => 2
278
+ p $~.bytebegin(1) # => 2
279
+ p $~.bytebegin(2) # => 6
280
+ p $~.bytebegin(3) # => 13
281
+ p $~.bytebegin(4) # => index 4 out of matches (IndexError)
282
+ #@end
283
+
284
+ #@samplecode シンボルを指定する例
285
+ /(?<key>\S+):\s*(?<value>\S+)/ =~ "name: ruby"
286
+ $~ # => #<MatchData "name: ruby" key:"name" value:"ruby">
287
+ $~.bytebegin(:key) # => 0
288
+ $~.bytebegin(:value) # => 6
289
+ $~.bytebegin(:foo) # => undefined group name reference: foo (IndexError)
290
+ #@end
291
+
292
+ --- byteend(n) -> Integer
293
+ --- byteend(name) -> Integer
294
+
295
+ n 番目の部分文字列終端のバイトオフセットを返します。
296
+
297
+ 0 はマッチ全体を意味します。
298
+ n 番目の部分文字列がマッチしていなければ nilを返します。
299
+
300
+ 引数に文字列またはシンボルを渡した場合は、対応する名前付きキャプチャの終端のバイトオフセットを返します。
301
+
302
+ @param n 部分文字列を指定する数値。
303
+ @param name 名前付きキャプチャを指定する文字列またはシンボル。
304
+
305
+ @raise IndexError 範囲外の n を指定した場合に発生します。
306
+ @raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。
307
+
308
+ #@samplecode 例
309
+ /(c).*(いう).*(e.*)/ =~ 'abcあいうdef'
310
+ p $~ # => #<MatchData "cあいうdef" 1:"c" 2:"いう" 3:"ef">
311
+ p $~.byteend(0) # => 15
312
+ p $~.byteend(1) # => 3
313
+ p $~.byteend(2) # => 12
314
+ p $~.byteend(3) # => 15
315
+ p $~.byteend(4) # => index 4 out of matches (IndexError)
316
+ #@end
317
+
318
+ #@samplecode シンボルを指定する例
319
+ /(?<key>\S+):\s*(?<value>\S+)/ =~ "name: ruby"
320
+ $~ # => #<MatchData "name: ruby" key:"name" value:"ruby">
321
+ $~.byteend(:key) # => 4
322
+ $~.byteend(:value) # => 10
323
+ $~.byteend(:foo) # => undefined group name reference: foo (IndexError)
324
+ #@end
325
+
326
+ #@end
327
+
256
328
--- post_match -> String
257
329
258
330
マッチした部分より後ろの文字列を返します([[m:$']]と同じ)。
0 commit comments