Issue #3388 has been updated by Eregon (Benoit Daloze).

File 0001-string.c-rb_str_start_with-rb_str_end_with-allow-Reg.patch added

Here is an attempt adding \A or \z to the Regexp's source and creating a new Regexp with it.
An alternative would be to call #to_s on the Regexp and add the anchor, but it seems cleaner to preserve options as global options.

What do you think?

akr: How would you cache the regexp structure?
----------------------------------------
Feature #3388: regexp support for start_with? and end_with?
https://bugs.ruby-lang.org/issues/3388#change-29048

Author: trans (Thomas Sawyer)
Status: Feedback
Priority: Normal
Assignee: 
Category: core
Target version: 2.0.0


=begin
 ruby-1.9.2-head > "aBcdeFghIj".start_with?(/abc/i)
 => false 
 
 In my implementation of start_with? it is easy enough to utilize #index, which works fine:
 
   def start_with?(pattern)
     index(pattern) == 0
   end
 
 But #end_with? is more difficult, and I had to use regular expressions.
 
     def end_with?(suffix)
       suffix = Regexp.escape(suffix) if String===suffix
       /#{suffix}$/.match(self) ? true : false
     end
 
 However, we might get rid of the '? true : false' and return the MatchData, since that could be useful information.
=end



-- 
http://bugs.ruby-lang.org/