Mohamed Mohamed - 1 year ago 176
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 ?

Answer Source

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):\/\/|)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download