scan(p1)
public
Tries to match with pattern at the current position. If there’s
a match, the scanner advances the “scan pointer” and returns the matched string. Otherwise, the scanner
returns nil.
s = StringScanner.new('test string')
p s.scan(/\w+/)
p s.scan(/\w+/)
p s.scan(/\s+/)
p s.scan(/\w+/)
p s.scan(/./)
Show source
/*
* call-seq: scan(pattern) => String
*
* Tries to match with +pattern+ at the current position. If there's a match,
* the scanner advances the "scan pointer" and returns the matched string.
* Otherwise, the scanner returns +nil+.
*
* s = StringScanner.new('test string')
* p s.scan(/\w+/) # -> "test"
* p s.scan(/\w+/) # -> nil
* p s.scan(/\s+/) # -> " "
* p s.scan(/\w+/) # -> "string"
* p s.scan(/./)
*
*/
static VALUE
strscan_scan(VALUE self, VALUE re)
{
return strscan_do_scan(self, re, 1, 1, 1);
}