From: "mame (Yusuke Endoh)" Date: 2012-11-02T22:12:04+09:00 Subject: [ruby-core:48759] [ruby-trunk - Bug #7092] StringScanner start-of-line matches false positives, while lookbehind for a newline gives false negatives Issue #7092 has been updated by mame (Yusuke Endoh). FYI: You may want to use StringScanner#beginning_of_line?. -- Yusuke Endoh ---------------------------------------- Bug #7092: StringScanner start-of-line matches false positives, while lookbehind for a newline gives false negatives https://bugs.ruby-lang.org/issues/7092#change-32239 Author: jayferd (Jay Adkisson) Status: Feedback Priority: Normal Assignee: mame (Yusuke Endoh) Category: Target version: 2.0.0 ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] To reproduce: >> 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 `m` flag. >> ss = StringScanner.new("a\nb") >> ss.scan(/../m) => "a\n" >> ss.scan(/(?<=\n)./m) # expecting "b", since the previous char is a newline => nil -- http://bugs.ruby-lang.org/