Forum: Ruby Re: Odd behavior of String#scan

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Daniel S. (Guest)
on 2005-12-22 02:45
(Received via mailing list)
> From: Dan D. [mailto:removed_email_address@domain.invalid]
>
> Will this do?
>
>   s="abcSTARTdef,ghi,jkl,ENDmno"
>   s.scan(/START(.*)END/).to_s.split(",")
>
>   => ["def", "ghi", "jkl"]


s="abcSTARTdef,ghi,jkl,ENDmno"
/START(.*)END/.match(s)[1].split(",")

Better conveys the intention to me, but YMMV.

#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################
#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared
by NetIQ MailMarshal
#####################################################################################
=?ISO-8859-1?Q?Florian_Gro=DF?= (Guest)
on 2005-12-22 03:24
(Received via mailing list)
Daniel S. wrote:

> s="abcSTARTdef,ghi,jkl,ENDmno"
> /START(.*)END/.match(s)[1].split(",")

s[/START(.*?)END/, 1].split(",") # :)
This topic is locked and can not be replied to.