るりまサーチ

最速Rubyリファレンスマニュアル検索!
88件ヒット [1-88件を表示] (0.052秒)
トップページ > クエリ:nil[x] > クエリ:at[x] > クラス:StringScanner[x]

別のキーワード

  1. _builtin nil?
  2. nilclass nil?
  3. object nil?
  4. _builtin nil
  5. object nil

ライブラリ

キーワード

検索結果

StringScanner#post_match -> String | nil (6248.0)

前回マッチを行った文字列のうち、マッチしたところよりも後ろの 部分文字列を返します。前回のマッチが失敗していると常に nil を 返します。

...ていると常に nil
返します。

//emlist[例][ruby]{
require 'strscan'

s = StringScanner.new('test string')
s.post_match # => nil
s.scan(/\w+/) # => "test"
s.post_match # => " string"
s.scan(/\w+/) # => nil
s.post_match # => nil
s.scan(/\s+/) # => " "
s.post_match # => "string"
s.sc...
...an(/\w+/) # => "string"
s.post_match # => ""
s.scan(/\w+/) # => nil
s.post_match # => nil
//}...

StringScanner#pre_match -> String | nil (6248.0)

前回マッチを行った文字列のうち、マッチしたところよりも前の 部分文字列を返します。前回のマッチが失敗していると常に nil を 返します。

...敗していると常に nil
返します。

//emlist[例][ruby]{
require 'strscan'

s = StringScanner.new('test string')
s.pre_match # => nil
s.scan(/\w+/) # => "test"
s.pre_match # => ""
s.scan(/\w+/) # => nil
s.pre_match # => nil
s.scan(/\s+/) # => " "
s.pre_match # => "test"
s.scan(...
.../\w+/) # => "string"
s.pre_match # => "test "
s.scan(/\w+/) # => nil
s.pre_match # => nil
//}...

StringScanner#matched -> String | nil (6236.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 (6236.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 run("EUC-JP") #=> 2
p run("Shift_Jis") #=> 2

//}

//emlist[例][ruby]{
require 'strscan'

s = StringScanner.new('test string')
s.matched_size # => nil
s.scan(/\w+/) # => "test"
s.matched_size # => 4
s.scan(/\w+/) # => nil
s.matched_size # => nil
//}...

StringScanner#match?(regexp) -> Integer | nil (6224.0)

スキャンポインタの地点だけで regexp と文字列のマッチを試します。 マッチしたら、スキャンポインタは進めずにマッチした 部分文字列の長さを返します。マッチしなかったら nil を 返します。

...マッチしなかったら nil
返します。

マッチしたサイズは文字単位でなくバイト単位となります。

//emlist[][ruby]{
require 'strscan'
def case1(encode)
utf8 = "\u{308B 3073 3044}"
s = StringScanner.new(utf8.encode(encode))
s.match?(/#{"\u{308B}".encode(enc...
...ode)}/)
end

p case1("EUC-JP") #=> 2
//}

@param regexp マッチに用いる正規表現を指定します。

//emlist[例][ruby]{
require 'strscan'

s = StringScanner.new('test string')
p s.match?(/\w+/) #=> 4
p s.match?(/\w+/) #=> 4
p s.match?(/\s+/) #=> nil
//}...

絞り込み条件を変える

StringScanner#matchedsize -> Integer | nil (6202.0)

StringScanner#matched_size と同じです。

...
StringScanner
#matched_size と同じです。

このメソッドは は将来のバージョンで削除される予定です。
代わりに StringScanner#matched_size を使ってください。

@see StringScanner#matched_size...

StringScanner#matched? -> bool (6107.0)

前回のマッチが成功していたら true を、 失敗していたら false を返します。

...失敗していたら 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
//}...

StringScanner#terminate -> self (3113.0)

スキャンポインタを文字列末尾後まで進め、マッチ記録を捨てます。

...[例][ruby]{
require 'strscan'

s = StringScanner.new('test string')
s.scan(/\w+/) # => "test"
s.matched # => "test"
s.pos # => 4
s[0] # => "test"
s.terminate
s.matched # => nil
s[0] # => nil
s.pos # => 11
//}

StringScanner
#clear は将来のバージョン...
...で削除される予定です。
代わりに StringScanner#terminate を使ってください。...