数学函数的正则表达式

时间:2013-12-30 22:27:09

标签: regex math

我正在研究ANSI C应用程序,其中输入可以是这样的-1 + (3*2) / sin(x^2)。允许必须是名为x的变量(没有其他变量),数字0-9,数学运算+ - * / ^,括号( )(没有其他类型)和函数abs, e^x, ln, log, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh

你能帮帮我,怎么做正则表达?感谢。

1 个答案:

答案 0 :(得分:3)

这个正则表达式应该有效:

(?:[0-9-+*/^()x]|abs|e\^x|ln|log|a?(?:sin|cos|tan)h?)+

Explanation here