method
start_with?
v2_1_10 -
Show latest stable
- Class:
String
start_with?(*args)public
Returns true if str starts with one of the prefixes given.
"hello".start_with?("hell") #=> true # returns true if one of the prefixes matches. "hello".start_with?("heaven", "hell") #=> true "hello".start_with?("heaven", "paradise") #=> false
2Notes
Starts with a Capital Letter
(or any regular expression you'd like)
'Abracadabra'[0..0] =~ /[A-Z]/ # => true
Starts with capital letter alternative
Just adding an anchor to the regular expression seems simpler (and was faster in my benchmarks, not that that matters much):
'Abracadabra' =~ /^[A-Z]/