-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
Hi!
Is there any way StringScanner could keep ^
meaningful? As it is, it denotes the current the beginning of the rest
, but not whether we're at the start of a line.
In the following example, "bar" is not expected to be stripped.
$ cat /tmp/foo.rb
require 'strscan'
def strip(str)
res = +''
s = StringScanner.new(str)
while !s.eos?
res <<
if s.scan(/foo/)
''
elsif s.scan(/^bar/)
''
else
s.scan(/./)
s.matched
end
end
res
end
p strip('foobarbaz')
$ ruby /tmp/foo.rb
"baz"
If there's no way for StringScanner to "fix" the ^
anchor, the documentation should warn about that.
Cheers!
Metadata
Metadata
Assignees
Labels
No labels