how can I validate youtube channel URL using REGEX ?
I found this pattern but it doesn’t work properly
/((http|https)://|)(www.|)youtube.com/(channel/|user/|)[a-zA-Z0-9]{1,}/
Can anyone help me ?
Advertisement
Answer
Your problem is the extra pipe after user/
Here is the corrected regex:
((http|https)://|)(www.|)youtube.com/(channel/|user/)[a-zA-Z0-9_-]{1,}
The reason this is a problem is because it make (channel|user) optional.
A better way to write this regex is
(https?://)?(www.)?youtube.com/(channel|user)/[w-]+