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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -