in reply to Re: Complex regex for maths formulas
in thread Complex regex for maths formulas

You shouldn't ever be using lexicals with (?{...}) or (??{...}) per ysth's note. That is almost always wrong. Also, your expression (??{ $skip }) is needlessly verbose and wasteful of runtime. Just interpolate $skip like qr/ ... $skip ... /x.

Your code can be implemented with proper recursion in 5.10:

{ my $skip = qr/\s*/; my $expr = qr/ (?<EXPR> # term $skip (?<TERM> [a-zA-Z]+ | [1-9]\d* | \( (?&EXPR) $skip \) ) # term* (?: $skip [-+*/] (?&TERM) )* ) /x; my $re = qr/^ $expr $skip \z/x; sub is_valid { shift =~ /$re/o } }

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^3: Complex regex for maths formulas
by quester (Vicar) on Nov 21, 2006 at 01:35 UTC
    Semi-off topic   Pardon me, but... what is the problem with using lexicals in (?{...}} or (??{...})?