ConFoo Montreal 2026: Call for Papers

Voting

: min(eight, two)?
(Example: nine)

The Note You're Voting On

Pedro Gimeno
10 years ago
Note that bracket style opening and closing delimiters aren't a 100% problem-free solution, as they need to be escaped when they aren't in matching pairs within the expression. That mismatch can happen when they appear inside character classes [...], as most meta-characters lose their special meaning. Consider these examples:

<?php
preg_match
('{[{]}', ''); // Warning: preg_match(): No ending matching delimiter '}'
preg_match('{[}]}', ''); // Warning: preg_match(): Unknown modifier ']'
preg_match('{[}{]}', ''); // Warning: preg_match(): Unknown modifier ']'
?>

Escaping them solves it:

<?php
preg_match
('{[\{]}', ''); // OK
preg_match('{[}]}', ''); // OK
preg_match('{[\}\{]}', ''); // OK
?>

<< Back to user notes page

To Top