Mohamed Mohamed - 4 months ago 60
PHP Question

Regex for youtube channel URL

how can I validate youtube channel URL using REGEX ?

I found this pattern but it doesn't work properly


Can anyone help me ?


Your problem is the extra pipe after user\/

Here is the corrected regex:


The reason this is a problem is because it make (channel|user) optional.

Also, consider using a question mark for optional instead of a extra pipe, so like this ((http|https):\/\/)? instead of this ((http|https):\/\/|)