class StringScanner
- StringScanner
- Reference
- Object
Overview
StringScanner provides for lexical scanning operations on a String.
NOTE To use StringScanner, you must explicitly import it with require "string_scanner"
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:
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
Defined in:
better_string_scanner.crInstance Method Summary
- #check(pattern, include_pattern)
- #check_until(pattern, include_pattern)
- #scan(pattern, include_pattern)
- #scan_until(pattern, include_pattern)
- #skip(pattern, include_pattern)
- #skip_until(pattern, include_pattern)