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
我也可能在一个字符串中有多个 this 的实例。
你能试试下面的
string = 'hey "user name":/users/50' matches = string.scan /"(?<name>[A-Za-z ]+)":\/users\/(?<user_id>\d+)/
matches将是一个包含具有 2 个元素的数组的数组,其中第一个元素是名称,第二个元素是 user_id
matches
>> matches # [['user name', 50]]