Sam Sweeney Sam Sweeney - 4 months ago 5x
Ruby Question

Regex in ruby. Selecting string from string with different amount of characters

I'm trying to select a number which varies in length from a string.

The number can be anywhere between 5 and 10 characters long.

For example, I have two different lengths of job numbers to extract from a string.

"job number:45678 date:01/01/16"
# => jobnumber = "45678"

"job number:123421312 date:03/03/16"
# => jobnumber = "123421312"


Looks like this just works:

"job number:45678 date:01/01/16"[/\d+/]
 => "45678" 

"job number:123421312 date:03/03/16"[/\d+/]
 => "123421312"