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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -