Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次の文字列を一致させてuser name50 にする方法はありますか?
user name
hey "user name":/users/50
文字列内にこれのインスタンスが複数ある場合もあります。
次のことを試してみてください
string = 'hey "user name":/users/50' matches = string.scan /"(?<name>[A-Za-z ]+)":\/users\/(?<user_id>\d+)/
matches2つの要素を持つ配列を含む配列になります。最初の要素は名前で、2番目の要素はuser_idです。
matches
>> matches # [['user name', 50]]