Is there a way to validate a user-provided regex pattern to avoid Regex Denial-of-Service (ReDoS) or arbitrary code execution attacks, assuming that also the subject (second argument of preg_match) is user-provided? I would like to use it like below:
<?php
function executeRegex($userProvidedRegex, $userProvidedInput) {
return preg_match($userProvidedRegex, $userProvidedInput);
}