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 } }
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
In reply to Re^2: Complex regex for maths formulas
by diotalevi
in thread Complex regex for maths formulas
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |