Created
November 5, 2017 09:14
-
-
Save bapspatil/e21193ffbb76b48f958bfbcce4e3c345 to your computer and use it in GitHub Desktop.
Get the video ID for a YouTube video from its YouTube URL
This file contains hidden or 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
| /* | |
| ** Created by bapspatil | |
| */ | |
| private static String extractVideoId(String ytUrl) { | |
| String vId = null; | |
| Pattern pattern = Pattern.compile("(?<=watch\\\\?v=|/videos/|embed\\\\/|youtu.be\\\\/|\\\\/v\\\\/|\\\\/e\\\\/|watch\\\\?v%3D|watch\\\\?feature=player_embedded&v=|%2Fvideos%2F|embed%\\u200C\\u200B2F|youtu.be%2F|%2Fv%2F)[^#\\\\&\\\\?\\\\n]*"); | |
| Matcher matcher = pattern.matcher(ytUrl); | |
| if (matcher.matches()){ | |
| vId = matcher.group(1); | |
| } | |
| return vId; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment