2015-10-26 25 views
1

多次掃描,說我有以下網址:調用在軌

url = "https://instagram.com/username/" 

而且我想提取「用戶名」。可以掃描3次嗎?或者這會變得更慢?

url.scan(/instagram.com\/.+\//).first.scan(/\/.+\//).first.scan(/[^\/]/).first 

回答

2

你可以嘗試這樣的事情:

url = "https://instagram.com/username/somewhat/something/" 

url.scan(/https:\/\/instagram.com\/(\w+)\//).first 
# => ["username"] 

Demonstration