2

Possible Duplicate:
Is there a regular expression to detect a valid regular expression?
Test if a string is regex

Given a string, I have a case where I want to be able to check if it is a regular expression. So far, the best approach I have is this:

<?php

function validate_regex($str){
    return preg_match($str, "anything here") !== false;
}

Is there a better way to check this?

Community
  • 1
  • 1
Anthony Bishopric
  • 1,306
  • 11
  • 23

0 Answers0