I am trying to make regex for embedding videos on YouTube.
Right now, this is the main job that I have:
http:\/\/www\.youtube\.com\/watch\?.*v=([a-z0-9-_]+)
It has a regular, recognized YouTube URL and then matches a unique video code. Unfortunately, this causes too many of my users. They enter it, skip HTTP, skip WWW, skip both HTTP and WWW, sometimes they enter it, replacing / watch? V = * c / v / *, and in all these scenarios it breaks the format.
What I'm trying to do is allow everything before and after "youtube.com" so that it is almost perfect, regardless of the input. Examples below ..
http:
http:
www.youtube.com/watch?v=([a-z0-9-_]+) --- missing HTTP
youtube.com/watch?v=([a-z0-9-_]+) --- missing HTTP and WWW
http:
http:
www.youtube.com/v/([a-z0-9-_]+) --- substituted watch?v= for /v/ AND missing HTTP
youtube.com/v/([a-z0-9-_]+) --- substituted watch?v= for /v/ AND missing HTTP and WWW
This is one change that I thought it should work (allow any character), but maybe I missed something?
[.]+\youtube\.com\/[.]+([a-z0-9-_]+)
, , . , , , . , , , , , . .
, .