Normalizing string for arithmetic expression evaluation in Java <p>I have a method that evaluates arithmetic expressions from a string, but it is very dependant on the format (all tokens should be separated with one space): </p> <pre><code>2 + 2 -2 + ( 7 / 5 ) * 6 </code></pre> <p>and so on. So I want to add method <code>Normalize()</code>, which would, well, normalize input string to the appropriate format (delete extra spaces, add necessacy spaces and handle uniry minus) and signal of errors, if any.<br> Initially, I wanted to use regular expression to check if line is actually an expression, but this only half of job. What is the best way to normalize the string in this case?</p>