说我有以下网址:
url = "https://instagram.com/username/"
我想提取"用户名"。可以扫描3次吗?或者这会慢得多吗?
url.scan(/instagram.com\/.+\//).first.scan(/\/.+\//).first.scan(/[^\/]/).first
答案 0 :(得分:2)
您可以尝试这样的事情:
url = "https://instagram.com/username/somewhat/something/"
url.scan(/https:\/\/instagram.com\/(\w+)\//).first
# => ["username"]