From: Mark Wilson Date: 2003-09-13T09:52:35+09:00 Subject: Re: String#start_with? / #end_with? On Friday, September 12, 2003, at 08:42 PM, dblack@superlink.net wrote: > [snip] > class String > > def start_with?(little_string) > !self.match(/^#{Regexp.escape(little_string)}/).nil? > end > > end > > [snip] > > big_string.start_with?(little_string) > All of the snippets in this thread will run aground on the fact that ^ > anchors to start-of-line, not start-of-string. You'd want to use the > \A anchor for the latter. !self.match(/\A#{Regexp.escape(little_string)}/).nil? I think this, and the corresponding 'end_with?' method, is now a good candidate for the String section of the Standard Class Extensions category on the RubyGarden Wiki. Regards, Mark