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?
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?
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.