Java regex matching the mathematical expression pattern -
i'm trying match string pattern recursively or iteratively.
term :- can variable(string) or integer
expression :- term + expression or term * expression or term / expression or term - expression
the idea find matching pattern mathematical expression this
zing^30*sin(45)+46*length-20
let's assume term ready.
as usual, i'll start bad one... in java.
[[term\\+]*[term\\*]*[term\\\]*[term\\-]*]+term
you're using wrong tool job. regular expressions can't describe grammars recursive syntaxes, definition. chomsky hierarchy. need expression parser. dijkstra shunting-yard algorithm, or 'recursive descent expression parser'.
Comments
Post a Comment