Re: Odd behavior of String#scan

From: Dan D. [mailto:[email protected]]

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
#####################################################################################

Daniel S. wrote:

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

s[/START(.*?)END/, 1].split(",") # :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs