Reputation: 38540
text = "I fixed bug #1234 and #7895 "
regex = /#(\d*)/
m = regex.match(text)
puts m.inspect #<MatchData "#1234" "1234">
In the above case why I am not seeing 7895? What's the correct solution?
Upvotes: 0
Views: 1437
Reputation: 411330
Regexps only match the first occurrence (or not at all, of course). #(\d*)
matches #1234
first, so that piece of text is returned.
If you want multiple matches, i.e., you want to search a string, use String#scan
or something similar.
Upvotes: 4