Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does preg_match(): Unknown modifier error occur?

\\    $DigitalSignature have full name value passed
$SignatureMatch =  '/' . strtolower( $NameFirst . ' ' . $NameLast ) . '$/';
if( true == preg_match( $SignatureMatch, strtolower( $DigitalSignature ) ) )
{
    $boolIsValid = true;
}

I am having this code for exact matching first name and last name match with digital signature. But this gives error reported me in error log on production(live).

preg_match(): Unknown modifier 'b'

I am unable to reproduce this error. How can I get this error firstly. And how to resolve this error for exact matching.

I have seen many questions on SO but not getting when will get this error. And how do I resolve that. Some of questions out of many I have saw are -

  1. Warning: preg_match() [function.preg-match]: Unknown modifier
  2. Unknown modifier in preg_match() statement
  3. Warning: preg_match() [function.preg-match]: Unknown modifier
  4. Unknown modifier 'l' error
  5. Unknown modifier 'g' PHP regex error
  6. Unknown modifier '/' in ...? what is it?
  7. preg_match() Unknown modifier '[' help
  8. Warning: preg_match() [function.preg-match]: Unknown modifier 'v'
  9. PHP Preg_match match exact word
  10. Unknown modifier 'v' when using preg_match() expression in regex
  11. preg_match(); - Unknown modifier '+'
  12. preg_match error Unknown modifier '{'
  13. Unknown modifier '(' when using preg_match() with a REGEX expression
like image 579
Somnath Muluk Avatar asked Jun 09 '26 10:06

Somnath Muluk


1 Answers

If the first name or last name contains a /, your regex will look something like:

/john/doe$/

To preg_match, this looks like the regex is /john/, with the trailing doe$/ being the modifiers. Those are of course invalid modifiers. You need to escape the regex delimiters (/) inside the regex itself using preg_quote.

like image 109
deceze Avatar answered Jun 10 '26 23:06

deceze