fork(1) download
  1. <?php
  2.  
  3. function is_valid_regex($pattern)
  4. {
  5. return is_int(@preg_match($pattern, ''));
  6. }
  7.  
  8. $patterns = array('/[[0-9]/i', '//(.*)/', '/(.*)-(.*)-(.*)/ ', '/([a-z]+)-([0-9_]+)/i');
  9.  
  10. foreach ($patterns as $pattern)
  11. {
  12. echo sprintf('%s is %b' . "\n", $pattern, is_valid_regex($pattern));
  13. }
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
/[[0-9]/i is 1
//(.*)/ is 0
/(.*)-(.*)-(.*)/  is 1
/([a-z]+)-([0-9_]+)/i is 1