るりまサーチ (Ruby 2.3.0)

最速Rubyリファレンスマニュアル検索!
3件ヒット [1-3件を表示] (0.186秒)

別のキーワード

  1. bigdecimal/util to_d
  2. float to_d
  3. integer to_d
  4. kernel $-d
  5. bigdecimal to_d

ライブラリ

クラス

キーワード

検索結果

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
//}