Created
March 18, 2021 06:13
-
-
Save abircse/b9bdfdfb9845f6503b730badcef43841 to your computer and use it in GitHub Desktop.
GetYoutubevideidfromurl
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
inline fun getYoutubevideidfromurl(youtubeurl: String) : String? | |
{ | |
if (youtubeurl.toLowerCase().contains("youtu.be")){ | |
return youtubeurl.substring(youtubeurl.lastIndexOf("/") + 1) | |
} | |
val pattern = "(?<=youtu.be/|watch\\?v=|/videos/|embed\\/)[^#\\&\\?]*" | |
val compiledPattern: Pattern = Pattern.compile(pattern) | |
val matcher: Matcher = compiledPattern.matcher(youtubeurl) | |
return if (matcher.find()) { | |
matcher.group() | |
} else null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment