I need to divide the string into “ABCD” and “12A2012” i.e. right at the
start of a number in the string
i can use str.partition(%r(\d)) which gives me [“ABCD”,“1”,“2A2012”]. I
can club the last two sub strings to get the work done. But is there a
better way to do so?
I need to divide the string into “ABCD” and “12A2012” i.e. right at the
start of a number in the string
i can use str.partition(%r(\d)) which gives me [“ABCD”,“1”,“2A2012”]. I
can club the last two sub strings to get the work done. But is there a
better way to do so?
I need to divide the string into “ABCD” and “12A2012” i.e. right at the
start of a number in the string
I just saw on ruby forum that you already had a solution that you liked.
Your reply did not show up on ruby talk (not in my inbox, anyway.)
Sorry for the noise.
2012/6/7 cyber c. [email protected]:
Regexp.new(/^([a-zA-Z]+)(.+)$/).match(str).captures
Why are you using Regexp.new, when /^([a-zA-Z]+)(.+)$/ already is a
Regexp? This seems nonsensical to me, like String.new(“abc”).
Yes, I’m used to store my regexps in some module/class constants and
usually use Regexp.new for some reason I don’t remember right now,
maybe because it allows passing a string which is useful in certain
cases:
Regexp.new(“^([a-zA-Z]+)(.+)$”)
But right, in my previous code I was passing a Regexp instance to
Regexp.new, which is not cool, sure