[thelist] Regular expression to check if other regularexpressions are valid

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Sat Jun 25 23:30:36 CDT 2005


Here is the response from RegExBuddy support team:

---------------------------------------------------------------------------------------------------------
(1)
First you need to define your regular expression flavor.  Many flavors
have limits to how many groups they allow, nested or not.  If there's a
limit, then you can use a regular expression to validate it.  If there is
no limit, then a regular expression cannot be used since it cannot keep
track of the depth of the nesting.

(2)
RegexBuddy uses its regex matching engine to tokenize regular expressions,
and uses additional logic to keep track of nested groups.  This is the
most practical way to do it, regardless of any nesting limits.  RegexBuddy
does not impose any limits.
------------------------------------------------------------------------------------------------------------

From (1) I understand that it is impossible to validate a infinitely-long
regular expression with a regular expression. and from (2) I
understand that tokenization is the choice.

HTH,
Volkan.


On 6/23/05, VOLKAN ÖZÇELİK <volkan.ozcelik at gmail.com> wrote:
> 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