Reputation: 5073
Say I have the following url:
url = "https://instagram.com/username/"
And I want to extract "username". Is it okay to scan 3 times? Or is this going to be much slower?
url.scan(/instagram.com\/.+\//).first.scan(/\/.+\//).first.scan(/[^\/]/).first
Upvotes: 1
Views: 37
Reputation: 44581
You can try something like this:
url = "https://instagram.com/username/somewhat/something/"
url.scan(/https:\/\/instagram.com\/(\w+)\//).first
# => ["username"]
Upvotes: 2