I think PHP itself will check the regex.
Here's a sample script I made :
// check for input, and set max size of input
if(@!empty($_POST['regex'])
&& @!empty($_POST['text'])
&& strlen($_POST['regex'])<1000
&& strlen($_POST['text'])<2000
){
// set script timeout in case something goes wrong (SAFE MODE must be OFF)
$old_time=ini_get('max_execution_time');
if(!set_time_limit(1)) die('SAFE MODE MUST BE OFF'); // 1 sec is more then enough
// trim input, it's up to you to do more checks
$regex=trim($_POST['regex']);
// don't trim the text, it can be needed
$input=$_POST['text'];
// escape slashes
$regex=preg_replace('/([\\/]+)?//', '\/', $regex);
// go for the regex
if(false===$matched=@preg_match('/'.$regex.'/', $input, $matches)){
// regex was tested, show results
echo 'Matches: '.$matched.'<br />';
if($matched>0){
echo 'matches: <br />';
foreach($matches as $i => $match){
echo $i.' = '.$match.'<br />';
}
}
}
// set back original execution time
set_time_limit($old_time);
}
Her neyse, NEVER EVER use eval() with user submitted strings.
Ayrıca, bazı basit, minimalist sanitizasyonunun yapabilir, ama bu size kalmış. ;)