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.
1c1e3bdfe006a22214102fcd6434a012?d=identicon&s=25 Daniel Sheppard (Guest)
on 2005-12-22 01:45
(Received via mailing list)
> From: Dan Diebolt [mailto:dandiebolt@yahoo.com]
>
> 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
#####################################################################################
E0ed615bd6632dd23165e045e3c1df09?d=identicon&s=25 =?ISO-8859-1?Q?Florian_Gro=DF?= (Guest)
on 2005-12-22 02:24
(Received via mailing list)
Daniel Sheppard 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.