Jan 15

RegEx to match YouTube IDs

Category: Linux,Perl   — Published by tengo on January 15, 2012 at 5:25 am

This regular expression here can be used to match YouTube IDs:

$youtube_url =~ /watch\?v=([\w-]{11})/;

In words: \w: match any alphanumeric chars including _ (the dash), means letters, numbers; also match - (the minus); match eleven chars.It ignores further url query parameters.