Forum: Ruby return all matched from a string

73700e119917433681f2e8f3e4369f74?d=identicon&s=25 Li CN (alex-osu3)
on 2017-03-18 21:33
Hi all,

I return the following script:

require 'pp'
pp  str.scan(/(q_Chapter.*png)/)


and ruby print out the following--1 element only

>ruby scan.rb
>Exit code: 0

I expect it prints out 2 elements as following.


How do I fix the problem?

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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.