I know first off that this is probably the worst looking regex ever but here goes.
I have this regex
(?:http://)?(?:www.)?youtu(?:be)?.(?:[a-z]){2,3}(?:[a-z/?=]+)([a-zA-Z0-9-_]{11})(?:[a-z0-9?&-_=]+)?
which is capable of matching any of these
www.youtu.be/watch?v=QH2-TGUlwu4
http://www.youtube.com/watch?v=QH2-TGUlwu4&feature=related
http://youtu.be/QH2-TGUlwu4
https://youtube.com/watch?v=QH2-TGUlwu4
https://youtube.com/watch?v=QH2-TGUlwu4%3Fversion%3D3%26amp%3Bhl%3Den_US
What it does in javascript is tears it apart and just returns the video code.
What I would like to happen is for it to return zero matches if the whole string starts with a double or single quote like so.
Here is where I lose all sense of what I am doing. I know what a negative lookahead is in theory but I found this somewhere else on the site and just plugged it in thinking it would solve problems.
If i put this ^(?!\") before it, it will return zero matches if anything is before the string.
Help?
Get rid of the
^. It’s constraining the match to the beginning of the string.