parsing - Spot vars and functions with regex in mathematical formulas -


i trying array of functions, , array of variables in mathematical formula in vanilla js :

a sample :

1+3*9/cos(4+2*x/6+pol)+ bdlire(longueur2)+2*8+sin(2) +g() 

for getting functions use : /([a-za-z]+)(?=[(])/gm https://regex101.com/r/ft3im7/1

for getting vars tried : /([a-za-z]+[a-za-z0-9]?)(?!\()/gm https://regex101.com/r/mg2fq2/1

but can see ignores last char of match followed ( char i'm bit stuck regex match variables.

thanks :)

you cannot use regex parse arithmetic expressions, maybe can, have flaky implementation , writing make go bonkers.

you need parsers. check out peg.js, easy use framework writing parsers compiles js, "vanilla" (whatever mean that...):

http://pegjs.org/


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -