I'm trying to validate that a string contains a regular expression, and that it is a valid one in PHP. Usually, I'd do this in the following way
<?php
@preg_match($string, '') !== false;
That generates a warning, which is fine because we use @
to suppress it. However, problems arise when we use set_error_handler
to catch errors, as the handler will still be triggered, despite the @
supressor.
I'd like to do something similar to the code provided, without it throwing a warning.
The warning thrown is:
preg_match(): Delimiter must not be alphanumeric or backslash