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
Post a Comment