PHP: preg_match - "The delimiter must not be alphanumeric or backslash"
Does anyone know what is wrong with this regex? It works fine on sites like RegexPal and RegExr, but in PHP it gives me this warning and no results:
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash
Here's my code:
preg_match('name="dsh" id="dsh" value="(.*?)"', 'name="dsh" id="dsh" value="123"', $matches);
+3
source to share
2 answers
You don't have a separator. Include the template in/
preg_match('/name="dsh" id="dsh" value="(.*?)"/', 'name="dsh" id="dsh" value="123"', $matches);
For templates that include /
themselves, it is recommended to use a different delimiter, for example ~
or #
to avoid escaping:
// Delimited with # instead of /
preg_match('#name="dsh" id="dsh" value="(.*?)"#', 'name="dsh" id="dsh" value="123"', $matches);
+9
source to share
You need delimiters :
preg_match('/name="dsh" id="dsh" value="(.*?)"/', 'name="dsh" id="dsh" value="123"', $matches);
+1
source to share