Return all matched from a string


#1

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,


#2

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


#3

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/