[thelist] How to tell if a regular expression is valid?

Joshua Olson joshua at waetech.com
Wed Jul 14 20:02:30 CDT 2004


> -----Original Message-----
> From: Jason Lustig
> Sent: Wednesday, July 14, 2004 6:59 PM
>
> So I'm working on a PHP script in which the user inputs a the search and
> replace sections of a regular expression in a form. For example, they
> might input "\[b\](.*?)\[\/b\]" (without the quotes) as the search
> section and "<b>\1</b>" as the replace part, and then the PHP script
> puts them together in the preg_replace() function.
>
> The only thing is, I want the script to check to see if the regular
> expressions they put in are valid, i.e. if they will work. I've done
> some searching on a regular expression to test if regular expressions
> are valid or something like that. Any ideas?

Jason,

You may want to consider actually using their expression as the search
criteria against a string.  Try/Catch any errors.  If there are any errors,
then the expression isn't valid.

<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com/service_areas/
706.210.0168




More information about the thelist mailing list