3件ヒット
[1-3件を表示]
(0.186秒)
検索結果
先頭3件
-
StringScanner
# matched -> String | nil (73051.0) -
前回マッチした部分文字列を返します。 前回のマッチに失敗していると nil を返します。
前回マッチした部分文字列を返します。
前回のマッチに失敗していると nil を返します。
//emlist[例][ruby]{
require 'strscan'
s = StringScanner.new('test string')
s.matched # => nil
s.scan(/\w+/) # => "test"
s.matched # => "test"
s.scan(/\w+/) # => nil
s.matched # => nil
s.scan(/\s+/) # => " "
s.matched # => " "
//} -
StringScanner
# matched _ size -> Integer | nil (37051.0) -
前回マッチした部分文字列の長さを返します。 前回マッチに失敗していたら nil を返します。
前回マッチした部分文字列の長さを返します。
前回マッチに失敗していたら nil を返します。
マッチしたサイズは文字単位でなくバイト単位となります。
//emlist[][ruby]{
require 'strscan'
def run(encode)
utf8 = "\u{308B 3073 3044}" # るびい
s = StringScanner.new(utf8.encode(encode))
s.scan(/#{"\u{308B}".encode(encode)}/)
s.matched_size
end
p run("UTF-8") #=> 3
p... -
StringScanner
# matched? -> bool (37033.0) -
前回のマッチが成功していたら true を、 失敗していたら false を返します。
前回のマッチが成功していたら true を、
失敗していたら false を返します。
//emlist[例][ruby]{
require 'strscan'
s = StringScanner.new('test string')
s.matched? # => false
s.scan(/\w+/) # => "test"
s.matched? # => true
s.scan(/\w+/) # => nil
s.matched? # => false
s.scan(/\s+/) # => " "
s.matched? # => true
//}