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...


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?

6 Years
Discussion Span
Last Post by dartiss

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);

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.



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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.