Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
there must be either a letter or a digit either side of an operator
parenthesis must open & close next to letters or digits, not next to operators, and do not have to exist
variables must not be more than one letter
Nothing other than a-z,A-Z,0-9,+,-,*,/,(,) can be used
I have got as far as this...
but is still limited as it only looks at (a + 3) and not anything beyond, like (3 * 4)+(b + x) or (5 - a)*z or even a simple 3 + 2.!~ \([a-zA-Z]?|[0-9]*\s[\+\-\*\/]?[a-zA-Z]?|[0-9]*\)
Can anyone offer a hand on how best to tackle this problem?
many thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Complex regex for maths formulas
by ikegami (Patriarch) on Nov 21, 2006 at 00:08 UTC | |
by diotalevi (Canon) on Nov 21, 2006 at 01:10 UTC | |
by quester (Vicar) on Nov 21, 2006 at 01:35 UTC | |
by diotalevi (Canon) on Nov 21, 2006 at 03:39 UTC | |
by ikegami (Patriarch) on Nov 21, 2006 at 01:36 UTC | |
by ysth (Canon) on Nov 21, 2006 at 00:46 UTC |