I'm trying to evaluate user input from a form field as a Regex expression to match against a URL using PHP's preg_match() function.
The user would be expected to enter a Regex expression like ^\/test\/(.*)\/?$
This input would be passed as a string literal to preg_match
as follows:
$url = $_SERVER['REQUEST_URI']; // /test/onetwothree/, for example
$regex = $_POST['regex__user_input']; // ^\/test\/(.*)\/?$
$match = preg_match($regex, $url);
This regex should match the pattern but preg_match
is not returning a result.
I think I need to add some delimiters or maybe use preg_quote()? I tried some variations but no dice.