StringScanner start-of-line matches false positives, while lookbehind for a newline gives false negatives
>> require 'strscan' >> ss = StringScanner.new("ab") >> ss.scan(/./) => "a" >> ss.scan(/^./) # expecting nil, since the head is in the middle of a line => "b"
As a workaround-that-didn't-work, I also tried looking behind for a newline, which seems never to match, even with the
>> ss = StringScanner.new("a\nb") >> ss.scan(/../m) => "a\n" >> ss.scan(/(?<=\n)./m) # expecting "b", since the previous char is a newline => nil
#3 [ruby-core:48758] Updated by mame (Yusuke Endoh) about 6 years ago
- Status changed from Open to Feedback
- Assignee set to mame (Yusuke Endoh)
- Target version set to 2.0.0
Sorry for late reply.
Honestly, it is difficult to say whether it is intended or a bug because there is no strscan maintainer.
But since 1.8, StringScanner#scan has behaved so. I guess there is some existing programs that depends on the behavior.
Therefore, I'd like not to change the behavior unless there is no special reason.
Do you have any special reason? Or do you just want to confirm?
Yusuke Endoh email@example.com