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 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.
Harry
···
On Fri, Jun 8, 2012 at 1:09 PM, Harry Kakueki <list.push@gmail.com> wrote:
I need to divide the string into "ABCD" and "12A2012" i.e. right at the
start of a number in the string
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
···
2012/6/8 Jan E. <lists@ruby-forum.com>:
"Iñaki Baz Castillo" <ibc@aliax.net> wrote in post #1063634:
2012/6/7 cyber c. <lists@ruby-forum.com>:
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").
On Fri, Jun 8, 2012 at 12:20 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
2012/6/8 Jan E. <lists@ruby-forum.com>:
"Iñaki Baz Castillo" <ibc@aliax.net> wrote in post #1063634:
2012/6/7 cyber c. <lists@ruby-forum.com>:
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: