I am developing a Calculator in JavaScript. Using the Regular Expressions and the formula below:
8.77 + $59.09 + 8 7.6 - ((1)) + 7e-2 + 4.9e11 + cos((pi/3) + 1) + cos(((6+3)) + 1) +1.12e+12 * x_variable + e - sin(((pi/4))) / tan(4)
how can I return the following array? If not possible with the use of RegEx, then with any other good strategies to achieve this?
['8.77', '$', '59.09', '87.6', '1', '7e-2', '4.9e11', 'cos', 'pi/3', '1', 'cos', '6+3', '1', '1.12e+12', 'x_variable', 'e', 'sin', 'pi/4', 'tan', '4']
I will also be happy with this result as well:
['8.77', '$', '59.09', '87.6', '1', '7e-2', '4.9e11', 'cos', 'pi', '3', '1', 'cos', '6', '3', '1', '1.12e+12', 'x_variable', 'e', 'sin', 'pi', '4', 'tan', '4']
Please note that the value of the standalone "e" is 2.7182818285, and "1.12e+12" is just an exponential number which contains "e" character, and "e" is at the end of "x_variable" string as well. Also, there are spaces in "8 7.6".