Php – preg_match with php Compilation failed

PHPpreg-matchregex

I try to match this expression :

* ^X-Spam-Flag: YES

I use this code :

if(preg_match('\'* ^X-Spam-Flag: YES\'', $value))

But i have this error :

PHP Warning: preg_match(): Compilation failed: nothing to repeat at
offset 0

Problem with regex and * and ^ but can i correct that ?

Best Answer

You are missing your delimiters.

Change to:

preg_match('#\'* ^X-Spam-Flag: YES\'#', $value)

Or maybe you need:

preg_match('#\* \^X-Spam-Flag: YES#', $value)