Project

General

Profile

Actions

Feature #3388

closed

regexp support for start_with? and end_with?

Added by trans (Thomas Sawyer) almost 14 years ago. Updated over 6 years ago.

Status:
Feedback
Target version:
-
[ruby-core:30585]

Description

=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


Files


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #13712: String#start_with? with regexpClosedActions
Has duplicate Ruby master - Bug #5536: String#start_with? and end_with? ignore arguments convertible to a String [PATCH]Closedmatz (Yukihiro Matsumoto)11/01/2011Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0