Page 1 of 1
Delimiter must not be alphanumeric or backslash
Posted: Mon Mar 08, 2010 9:06 pm
by Cirdan
So I'm trying to preg_match the following regex, but it's giving me a "Delimiter must not be alphanumeric or backslash." I Googled the error, but the solutions were to add the slashes to the beginning and end of the statement. I already have those.
Code: Select all
/http:\/\/www\.youtube\.com\/watch\?v=(.*?)(\&(.*?))?/
Re: Delimiter must not be alphanumeric or backslash
Posted: Tue Mar 09, 2010 1:32 am
by ridgerunner
Your regex has valid syntax and does not generate any error when I place it directly into preg_match. However, it does fail to match the video value (group 1) because both dot-stars are lazy and can match nothing, and thus the regex successfully finishes before actually capturing anything. Changing each dot to a "not ampersand" and removing the lazy ? from the stars fixes the problem like so:
Code: Select all
<?php
$data = "http://www.youtube.com/watch?v=dkjdfij&v1=one&v2=two";
$re = '/http:\/\/www\.youtube\.com\/watch\?v=([^&]*)((?:\&[^&]*+)*)/';
if (preg_match($re, $data, $matches)) {
print_r($matches);
}
else echo "No match\n";
?>

Re: Delimiter must not be alphanumeric or backslash
Posted: Tue Mar 09, 2010 9:49 am
by pickle
I'd just make my life simpler and use something else for the delimiter, such as ":".
Re: Delimiter must not be alphanumeric or backslash
Posted: Tue Mar 09, 2010 5:29 pm
by Cirdan
Ah...the problem wasn't in my regex, it was because in an array I was passing to a third party library wasn't formatted right

Thanks tho