Re: regular expression gurus--help!



Hi --

On Mon, 22 Jun 2009, Harry Kakueki wrote:

On Sun, Jun 21, 2009 at 9:26 PM, Sebastian
Hungerecker<sepp2k@xxxxxxxxxxxxxx> wrote:

"abcdefghijkl".scan(/(.)(?=(..))/).map(&:join)
=> ["abc", "bcd", "cde", "def", "efg", "fgh", "ghi", "hij", "ijk", "jkl"]

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

.



Relevant Pages

  • [HPADM] SUMMARY: Listing explicit directories using regular expressions
    ... David Lodge, David Lee Totsch and Bill Hassell hit the nail on the head - ... ls/ll doesn't know anything at all about regular expressions. ... Intec Telecom Systems PLC does not represent or warrant that an attachment ...
    (HP-UX-Admin)
  • Re: nil.to_i returning zero
    ... Upcoming training from Ruby Power and Light, ... Advancing with Rails, Edison, NJ, November 6-9 ... Both taught by David A. Black. ...
    (comp.lang.ruby)
  • Re: Making a random string
    ... microscopic scale, you should be writing in C. ... I don't think the distinction is between success and failure, ... David A. Black / Ruby Power and Light, ...
    (comp.lang.ruby)
  • Re: [opensuse] regexp -- defference between < and  ?
    ... On Tuesday 29 April 2008 17:58, David C. Rankin wrote: ... With regular expressions, what is the difference between \< and \b? ...
    (SuSE)
  • Re: Class instance variable idiom
    ... Upcoming training from Ruby Power and Light, ... Advancing with Rails, Edison, NJ, November 6-9 ... Both taught by David A. Black. ...
    (comp.lang.ruby)