I'm not sure if this is a bug or intentional behavior, so I thought I would
post it here to see what the community thought of what was happening. If you
set up a StringScanner object to perform iterative matching on a string the
behavior of \A and ^ seem to always match. It seems to me that \A should
only match if it is the first match performed, and ^ should only match if
bol? returns true, which should be after a \n or if it is the first match
performed. Here is some code I ran in irb to illustrate the problem:
require 'strscan'
sc = StringScanner.new("the white elephant eats grass")
sc.scan(/the\s+/)
sc.bol?
sc.scan(/^white\s+/)
sc.scan(/\Aelephant\s+/)
this code produced the following result.
irb(main):001:0> require 'strscan'
=> true
irb(main):002:0> sc = StringScanner.new("the white elephant eats grass")
=> #<StringScanner 0/29 @ "the w...">
irb(main):003:0> sc.scan(/the\s+/)
=> "the "
irb(main):004:0> sc.bol?
=> false
irb(main):005:0> sc.scan(/^white\s+/)
=> "white "
irb(main):006:0> sc.scan(/\Aelephant\s+/)
=> "elephant "
Any thoughts and or advice on this matter are greatly appreciated.
-John Halderman