I want to divide a math equation with regular expression, but I'm upset with a point.
We will see as an example: 3x ^ 3 + 2x ^ 2-6x * -3
After dividing by some regular expressions, I I want to get this result:
I hope the result:
[0] 3x ^ 3 [1] + 2x ^ 2 [2] -6x [3 ] * -3
I am trying with this RE: (? = (\\ * - | \\ - | \\ + | \\ * | \ \ /))
after equation.split ("(? = (\\ * - | \\ - | \\ + | \\ * | \\ /) ) "
The result is:
[0] 3x ^ 3 [1] + 2x ^ 2 [2] -6x [3] * [4] -3
I can not remove that part - \\ -
- Because, if my string was: 3x ^ 3 + 2x ^ 2-6x-3
I will be expected:
[0] 3x ^ 3 [1] + 2x ^ 2 [2] -6x [3] -3
As you can see, my problem is that I write an RE which is * - < / Code> or only matches
*
or -
I think, You have to add a negative attitudes - you only want to split on hyphen if it's a (? >
*
: < / P>
< / Div> equation.split ("(? = (? & Lt;! \\ *) - | \\ + | \\ * | /)")
No comments:
Post a Comment