I use the following RegEx to basically filter out any text and accept the numeric + operators.
([-+]?[0-9]*\.?[0-9]+[\/\+\-\*])+([-+]?[0-9]*\.?[0-9]+)
Thus, it captures 1 + 1, 1-1, 2 * 2, 10/2, etc. Since the solution that I write does not just evaluate the expression in the string, but also sums up all the calculated strings in total, I need to allow users to put separate positive / negative numbers, which will affect the total number (500, -500, +500 (check fool)).
Here is the test that I performed. I need to be able to match +500, -500 and 500 in test cases, still excluding any text. I am absolutely terrible with RegEx, so any help is greatly appreciated!
source
share