Reputation: 1
Ruby => How to match a string that contains #and a number example #56
for example i have a string "my roll number is #256767"
i should match whether the string has # symbol and a number beside it
Upvotes: 0
Views: 506
Reputation: 70929
Use something like:
m = s.match(/^.*(#\d+).*$/)
unless m.nil?
puts m[1]
end
Upvotes: 0