class StringScanner
- StringScanner
- Reference
- Object
Overview
StringScanner
provides for lexical scanning operations on a String
.
Example
require "string_scanner"
s = StringScanner.new("This is an example string")
s.eos? # => false
s.scan(/\w+/) # => "This"
s.scan(/\w+/) # => nil
s.scan(/\s+/) # => " "
s.scan(/\s+/) # => nil
s.scan(/\w+/) # => "is"
s.eos? # => false
s.scan(/\s+/) # => " "
s.scan(/\w+/) # => "an"
s.scan(/\s+/) # => " "
s.scan(/\w+/) # => "example"
s.scan(/\s+/) # => " "
s.scan(/\w+/) # => "string"
s.eos? # => true
s.scan(/\s+/) # => nil
s.scan(/\w+/) # => nil
Scanning a string means remembering the position of a scan offset, which is just an index. Scanning moves the offset forward, and matches are sought after the offset; usually immediately after it.
Method Categories
Methods that advance the scan offset:
#scan
#scan_until
#skip
#skip_until
Methods that look ahead:
#peek
#check
#check_until
Methods that deal with the position of the offset:
#offset
#offset=
#eos?
#reset
#terminate
Methods that deal with the last match:
#[]
#[]?
Miscellaneous methods:
#inspect
#string