2017-10-18 228 views
-2

我有這些網址:抽取信道/用戶從YouTube的URL與正則表達式

$url1 = 'https://www.youtube.com/user/funradio/about?disable_polymer=1'; 
$url2 = 'https://www.youtube.com/channel/UCM3A_8gPv_TbaMZQZxsvT3A/about'; 
$url3 = 'channel/UCM3A_8gPv_TbaMZQZxsvT3A/about'; 

我想提取:

user/funradio 
channel/UCM3A_8gPv_TbaMZQZxsvT3A 
channel/UCM3A_8gPv_TbaMZQZxsvT3A 

任何想法?

非常感謝

+0

歡迎堆棧溢出。你已經嘗試過這麼做了嗎?請回顧[預計需要多少研究工作?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users)。堆棧溢出不是一種編碼服務。您需要研究您的問題,並嘗試在發佈之前親自編寫代碼。如果遇到某些特定問題,請返回幷包含[最小,完整和可驗證示例](https://stackoverflow.com/help/mcve)以及您嘗試的內容摘要,以便我們提供幫助。 – Sand

+0

你能通過編輯這個問題發佈你的代碼嗎? –

回答

0

這將匹配所有3串

/user/(.*?)/|(channel/.*?)/ 
+0

感謝Dustin,我做了一些更改,您可以從這裏查看:https://regex101.com/r/uD4tK6/6 我無法正確獲取最後兩個網址,您怎麼看? – Playinteractive