Page 1 of 1

My preg_match isn't work with the variable - why is this?

Posted: Wed Mar 12, 2014 4:53 am
by simonmlewis

Code: Select all

$email = isset($_POST['email']) ? $_POST['email'] : null;
$find = "*";
if(preg_match("/$find-\d/", $email))  {
    echo "matched";
}
This isn't working.
[text]Warning: preg_match(): Complication failed: nothing to repeat at offset 0.[/text]

I'm trying to find * in the email address. and act upon that.

Re: My preg_match isn't work with the variable - why is this

Posted: Wed Mar 12, 2014 7:34 am
by Celauran
* has special meaning in regular expressions, so you'll need to escape it.

Code: Select all

preg_match('/\*-\d/', $email);

Re: My preg_match isn't work with the variable - why is this

Posted: Wed Mar 12, 2014 8:04 am
by simonmlewis
Yeah sorry to say, I worked that out a few hours ago, but forgot to post it here.
Thanks tho.