I want to get the numbers out of strings such as:
person_3
person_34
person_356
city_4
city_15
etc...
It seems to me that the following should work:
string[/[0-9]*/]
but this always spits out an empty string.
I want to get the numbers out of strings such as:
person_3
person_34
person_356
city_4
city_15
etc...
It seems to me that the following should work:
string[/[0-9]*/]
but this always spits out an empty string.
[0-9]*
successfully matches "0 or more" digits at the beginning of the string, so it returns ""
. [0-9]+
will match "1 or more" digits, and works as you expect:
irb(main):001:0> x = "test 92"
=> "test 92"
irb(main):003:0> x[/\d*/]
=> ""
irb(main):005:0> x.index(/\d*/)
=> 0
irb(main):004:0> x[/\d+/]
=> "92"