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' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -