regex pattern /}/ sometimes matches } and sometimes doesn’t.
Is there any know bug in PHP?
I am using PHP 5.40
I am assuming that } doesn’t need to be escaped for match.
Although /\}/ always matches } but this behavior seems to be wrong.
This link also says 11 metacharacters that need to be escaped only.
there are 11 characters with special meanings: the opening square bracket [, the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening round bracket ( and the closing round bracket ). These special characters are often called “metacharacters”.
for an example - is a metacharacter as per PHP documentation but that doesn’t need to be escaped and /-/ works fine in PHP, why not }?
$subject = 'find me}';
$pattern = '/}/';
$isMatch = preg_match($pattern,$subject,$matches);
echo 'Match Found = ' . $isMatch . '<br />';
print_r($matches);
sometimes i get following
Match Found = 0
Array ( )
sometimes i get following
Match Found = 1
Array ( [0] => } )
http://php.net/manual/en/function.preg-quote.php according to that { and } are regular expression characters