Re: regular expression gurus--help!
- From: "David A. Black" <dblack@xxxxxxxxxxx>
- Date: Sun, 21 Jun 2009 20:32:12 -0500
Hi --
On Mon, 22 Jun 2009, Harry Kakueki wrote:
On Sun, Jun 21, 2009 at 9:26 PM, Sebastian
Hungerecker<sepp2k@xxxxxxxxxxxxxx> wrote:
=> ["abc", "bcd", "cde", "def", "efg", "fgh", "ghi", "hij", "ijk", "jkl"]"abcdefghijkl".scan(/(.)(?=(..))/).map(&:join)
HTH,
Sebastian
I am not the OP, but thanks for that solution.
I learned more about regular expressions and relearned something about scan.
It did not work on my machine so I changed it to this.
p "abcdefghijkl".scan(/(.)(?=(..))/).map{|x| x.join}
Is this map(&:join) using 1.9?
Yes. In general, &obj in that position triggers the use of obj.to_proc
as the code block for the method call, and in 1.9 there's a built-in
Symbol#to_proc method.
David
--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (http://manning.com/black2)
"Ruby 1.9: What You Need To Know" Envycasts with David A. Black
http://www.envycasts.com
.
- Follow-Ups:
- Re: regular expression gurus--help!
- From: Robert Dober
- Re: regular expression gurus--help!
- References:
- regular expression gurus--help!
- From: timr
- Re: regular expression gurus--help!
- From: Sebastian Hungerecker
- Re: regular expression gurus--help!
- From: Harry Kakueki
- regular expression gurus--help!
- Prev by Date: Re: regular expression gurus--help!
- Next by Date: Re: Product Class #2
- Previous by thread: Re: regular expression gurus--help!
- Next by thread: Re: regular expression gurus--help!
- Index(es):
Relevant Pages
|