[ad_1]
I’m trying to make a parser focusing on getting all the expressions into a list.
Given the following math functions:
f(x) = (3x^2) + 2/x + 10
f(x) = (-3)x^e + (2(x^x))
f(x) = log(10^e+x^(10-x))
I want to find a regex to split these approaches as follows:
['(3x^2)', '+2/x', '+10']
['(-3)x^e', '+(2(x^x))']
['log(10^e+x^(10-x)']
I have found something, but doesn’t work as expected.
((?:^|[+-])[0-9]*)(?:\*?x(?:\^[0-9]+)?)?
It works only for polynomials such as 3x^2 + 2x - 1
etc.
For example, let’s consider the following match (-3x&25)
where &
could be one of the following symbols ['-', '+', "https://stackoverflow.com/", '*', '^']
-
(-3x&25)
should be part of a group 1 -
-3x
should be part of a group 2 -
25
should be part of a group 3
For example, if we have an expression like (expression1&expression2)
expression1
can be (3x&e^10)
where &
could be one of the following symbols ['-', '+', "https://stackoverflow.com/", '*', '^']
and then apply the rules described above.
But if the expression has '(', ')'
(ex. (3x-2(3x-2))
) the matches should be: ['3x', '-2(3x-2)']
, not ['3x', '-2(3x', '-2)']
[ad_2]