Created
October 6, 2012 14:42
-
-
Save jamiehs/3845089 to your computer and use it in GitHub Desktop.
YouTube JavaScript Regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var youTubeRegex = /(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|[a-zA-Z0-9_\-]+\?v=)([^#\&\?\n<>\'\"]*)/gi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Different Video ID formats (random sample) --> | |
http://youtu.be/oHg5SJYRHA0 | |
http://youtu.be/vOTfkVfMoec | |
http://youtu.be/UAqAqGMb_jQ | |
http://youtu.be/q4d8C7vSEdc | |
http://youtu.be/YmUi22qZdkA | |
http://youtu.be/m86Yq6vC_bY | |
http://youtu.be/__CR1plT1tQ | |
<!-- DIfferent URL formats --> | |
http://www.youtube.com/watch?v=oHg5SJYRHA0&feature=feedrec_grec_index | |
<a title="A YouTube Video" href="http://www.youtube.com/watch?v=zV-Jjqth9jQ" target="_blank">A YouTube Video</a> | |
http://www.youtube.com/user/IngridMichaelsonVEVO#p/a/u/1/QdK8U-VIH_o | |
<a title="A YouTube Video" href="http://www.youtube.com/user/IngridMichaelsonVEVO#p/a/u/1/QdK8U-VIH_o" target="_blank">A YouTube Video</a> | |
http://www.youtube.com/v/oHg5SJYRHA0?fs=1&hl=en_US&rel=0 | |
<a title="A YouTube Video" href="http://www.youtube.com/v/oHg5SJYRHA0?fs=1&hl=en_US&rel=0" target="_blank">A YouTube Video</a> | |
http://www.youtube.com/watch?v=oHg5SJYRHA0#t=0m10s | |
<a title="A YouTube Video" href="http://www.youtube.com/watch?v=oHg5SJYRHA0#t=0m10s" target="_blank">A YouTube Video</a> | |
http://www.youtube.com/embed/oHg5SJYRHA0?rel=0 | |
<a title="A YouTube Video" href="http://www.youtube.com/embed/oHg5SJYRHA0?rel=0" target="_blank">A YouTube Video</a> | |
http://www.youtube.com/watch?v=oHg5SJYRHA0 | |
<a title="A YouTube Video" href="http://www.youtube.com/watch?v=oHg5SJYRHA0" target="_blank">A YouTube Video</a> | |
http://youtu.be/oHg5SJYRHA0 | |
<a title="A YouTube Video" href="http://youtu.be/0zM3nApSvMg" target="_blank">A YouTube Video</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the HTML above to test the Regex. I'm currently using this Regex in my "Related Service Comments" plugin where I'm attempting to find YouTube URLs in the content, regardless of the format.