Reputation: 1127
I have a situation where the end user is allowed to enter an arbitrary regex expression (php pcre). EG: ^[a-zA-Z]foo[0-9]{3}$
I need to 'validate' this regex both for:
^[a-zA-Z0-9_\-]$
What is a good way (ideally in php) to perform the 2 validations above?
Note: I am not able to at runtime to simply use both regex expressions for matching each string.
Upvotes: 0
Views: 126
Reputation: 23216
That's impossible. PCRE is a turing complete language, so in essence you're trying to solve the halting problem. The only way to do it is to simply run the PCRE and check for errors.
Upvotes: 7