I’m just posting this here for those of you who want a quick way to grab that YouTube video key from a URL. First off, I snagged the following regex from this StackOverflow post. It looks like this:
I gave it a test drive in RegexHero and it seemed to work quite well. There are more complicated solutions out there but this seems to do the job. The video key shows up in the second regex group (or group number one). To get the key we run a
Regex.Match and grab the value of that second group:
Now you can store that in the database and recreate embed code on the fly.
Understanding how a programming language works is a surefire way to be a better developer. Read more.