Member Avatar for dartiss

Morning,

I'm attempting to perform a preg_match against a regular expression to identify whether it's a YouTube video or not. I've got, I'll admit, the regular expression from elsewhere...

\s(https?:\/\/www.youtube(?:-nocookie)?.com\/(?:v|embed)\/([a-zA-Z0-9-]+)).

This appears to work fine. However, I'm getting the following error when I attempt the preg_match...

WARNING: [filename].php:[line] - preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash

Looking at other similar regular expressions I think the format isn't quite right as they appear to use hashes around the expression. However, I'm at a lose at what to do with it to get it to work the same (I've had a tinker - the error went but nothing matched either).

Can anybody help me out with this?
David.

Looks like you forgot to add the delimiter. Your preg should look something like this (note the percent sign):

preg_match('%\s(https?://www.youtube(?:-nocookie)?.com/(?:v|embed)/([a-zA-Z0-9-]+))%i', $subject);
Member Avatar for dartiss

Thanks for that. Unfortunately, it still doesn't work - no errors but not triggering. I don't think the expression is correct and I don't understand them well enough to correct it.

If anybody is a whiz with them and can construct one that works with YouTube URLs, please let me know.

David.

Member Avatar for dartiss

Thanks for the offer. I've since realised, embarrassingly, that I don't know the answer to your question. I'm not sure I will do either, so I'll consider this solved. Sorry for wasting your time - I'll post again if I am able to answer that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.