Issue #5351 has been updated by Alan Walkings. Found the same issue with Ruby Enterprise Edition 2011.04 http://informatique.edublogs.org/ ---------------------------------------- Bug #5351: String#start_with? resets pattern matching results http://redmine.ruby-lang.org/issues/5351 Author: Ivan Kuznetsov Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03 String#start_with? backported into 1.8.7 (https://github.com/ruby/ruby/commit/7d848354f8e25a652ccaabbd54e106b44e7da308) has an undocumented behaviour - it resets pattern matching results Example code: "Hello".sub!(%r(^(.))) {} puts "$1 after sub! = '#{$1}'" "Hello".start_with?("H") puts "$1 after start_with? = '#{$1}'" Ruby 1.8.7: $1 after sub! = 'H' $1 after start_with? = '' Ruby 1.9.X: $1 after sub! = 'H' $1 after start_with? = 'H' In Ruby 1.8.7 rb_str_start_with for some reason calls rb_reg_search. In 1.9.X solution is more elegant - memcmp is used: https://github.com/ruby/ruby/blob/ruby_1_9_3/string.c#L7170 -- http://redmine.ruby-lang.org