How to find last occurrence of a number in a string using Ruby?

Viewed 21876

Using Ruby... given the following string:

x = "blah_blah.do.dah[4543]junk_junk"

How do I remove all text after the last number/digit?

I thought the easiest way to do this might be by finding the index of last occurrence and then removing everything after that index. However, I can't seem to figure out how to obtain that index. All my attempts at using regex have failed.

7 Answers
Related