Forum: Ruby return all matched from a string

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.
73700e119917433681f2e8f3e4369f74?d=identicon&s=25 Li CN (alex-osu3)
on 2017-03-18 21:33
Hi all,

I return the following script:

###
require 'pp'
str='q_Chapter1_4.png|q_Chapter1_4_2.png|a_Chapter1_4.png'
pp  str.scan(/(q_Chapter.*png)/)

###

and ruby print out the following--1 element only

>ruby scan.rb
[["q_Chapter1_4.png|q_Chapter1_4_2.png|a_Chapter1_4.png"]]
>Exit code: 0


I expect it prints out 2 elements as following.

[["q_Chapter1_4.png","q_Chapter1_4_2.png"]]


How do I fix the problem?

thanks,
73700e119917433681f2e8f3e4369f74?d=identicon&s=25 Li CN (alex-osu3)
on 2017-03-19 14:15
problem solved.

add '?' to this line as follows:
pp  str.scan(/(q_Chapter.*?png)/)

>ruby scan.rb
[["q_Chapter1_4.png"], ["q_Chapter1_4_2.png"]]
>Exit code: 0
02c8490928c5546aaef1ec6f5616f50c?d=identicon&s=25 Kidz Kul (ronn91)
on 2017-04-04 05:02
That’s what I was looking for.Very nice blog indeed,thank you so much
admin
http://wordcookiesgame.com/
http://hillclimbracing-2.com/
http://fivenightsatfreddys-4.com/
http://hotmailcomsignin.email/
This topic is locked and can not be replied to.