Sam Sweeney Sam Sweeney - 5 months ago 17
Ruby Question

Selecting string of variable length from string

I'm trying to select a number from a string. The number can be between 5 and 10 characters long. For example, I have two 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"

Answer

looks like this just works:

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

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