[thelist] Regular expression to check if other regularexpressions are valid
VOLKAN ÖZÇELİK
volkan.ozcelik at gmail.com
Wed Jun 22 22:21:08 CDT 2005
try {
eval("preg_match('/badregex', 'asdfasf');");
}
catch(exception) {
alert("bad reg ex");
}
will do it for JS.
However what we are thinking (at least what I am thinking) is something like
/bad regex**/
----------------^ (the arrow points the second asterix)
which will indicate the character position of the error.
This can only be done by checking the syntax of regex (with a reg ex,
with a recursive programming logic, with some other logic) imo.
Cheers,
Volkan
On 6/23/05, lustig at brandeis.edu <lustig at brandeis.edu> wrote:
> > If eval is available in your language of choice you can
> > use it to test the validity of a regex.
>
> But if you just eval the regular expression, like this (in php)
>
> eval("preg_match('/badregex', 'asdfasf');");
>
> ... then wouldn't it just throw an error as if you ran the code natively? In
> my experience, eval() doesn't suppress errors.
>
> Jason
> --
>
> * * Please support the community that supports you. * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>
More information about the thelist
mailing list