Youtube video player

I know this is a little old but here are two links to other members who had similar issues with regex and getting the correct data out:

This regEx pattern I find is the best. Extract with Regex empty - #11 by sudsy

This is useful if you want to get the image also:

What I did was this:

I have a standard Youtube element and pull in the a custom field from the database:

When saving the input to the database I use regex on this to extract and only save the youtube ID:

image
(?<=v=|v/|embed/|be/)([^&?]+)

I also show an alert if the input is invalid using the same regex but looks to see if the regex didn’t return anything - which i determine is invalid, but you may have your own ideas here.
image

3 Likes