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

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

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -