self[nth] -> String | nil[permalink][rdoc][edit]-
前回マッチした正規表現の nth 番目のかっこに対応する部分文字列を返します。インデックス 0 はマッチした部分全体です。前回のマッチが失敗していると常に nil を返します。
- [PARAM]
nth: - 前回マッチした正規表現の nth 番目のかっこに対応する部分文字列を返します。
require 'strscan' s = StringScanner.new('test string') p s.scan(/\w(\w)(\w*)/) # => "test" p s[0] # => "test" p s[1] # => "e" p s[2] # => "st" p s.scan(/\w+/) # => nil p s[0] # => nil p s[1] # => nil p s[2] # => nil p s.scan(/\s+/) # => " " p s[0] # => " " p s[1] # => nil p s[2] # => nil p s.scan(/\w(\w)(\w*)/) # => "string" p s[0] # => "string" p s[1] # => "t" p s[2] # => "ring" - [PARAM]