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?

4

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.