Regex URL for YouTube channel URL.
2 answers
Your problem is the extra pipe after user\/
Here's the corrected regex:
((http|https):\/\/|)(www\.|)youtube\.com\/(channel\/|user\/)[a-zA-Z0-9\-]{1,}
The reason this is a problem is because it makes (channel | user) optional.
Also, use a question mark for optional instead of an additional channel, so instead of ((http|https):\/\/)?
((http|https):\/\/)?
((http|https):\/\/|)
+8
source to share
To get the channel name or channel ID from the YouTube url use:
(?:https|http)\:\/\/(?:[\w]+\.)?youtube\.com\/(?:c\/|channel\/|user\/)?([a-zA-Z0-9\-]{1,})
Works for:
- https://www.youtube.com/user/channelblabla
- https://www.youtube.com/channel/channelblabla
- https://www.youtube.com/c/channelblabla
- https://www.youtube.com/channelblabla
The channel identifier starts with "UC". I don't know of any other way to recognize channel names and channel names.
0
source to share