Issue
How to use dart regex to extract YouTube video ID from video URL?
Example URL
https://www.youtube.com/watch?v=SEkUienM2oY&t=1265s
or
https://m.youtube.com/watch?v=SEkUienM2oY&t=1265s
Return
SEkUienM2oY&t=1265s
Its working for me
String getVideoID(String url) {
url = url.replaceAll("https://www.youtube.com/watch?v=", "");
url = url.replaceAll("https://m.youtube.com/watch?v=", "");
return url;
}
but how to do this with Regex??
Solution
If all our URLs are similar to our input string in the question, we can simply just extract those IDs with an expression similar to:
.*\?v=(.+?)&.+
and our desired output is in this capturing group: (.+?)
Demo
Reference
It seems we'd have 11 alphanumeric chars [A-Za-z0-9]{11} for that ID. That might be something unique if you'd want to design sophisticated expressions:
Answered By - Emma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.