ruby on rails - matching string then returning results using regexp -


is there way match following string user name , 50?

hey "user name":/users/50 

i may have more 1 instance of in string.

can try following

string = 'hey "user name":/users/50' matches = string.scan /"(?<name>[a-za-z ]+)":\/users\/(?<user_id>\d+)/ 

matches array containing arrays 2 elements first element name , 2nd element user_id

>> matches # [['user name', 50]] 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -