title: Regex issue with infix expression in Java
body: <p>I'm trying to create a Java program that is able to follow the order of operations when infix expressions are entered. To simplify input I've decided it would be best to split the entire String by using a <code>regex</code> expression. I've been able to split everything except the <code>6 3</code> into their own <code>String</code> values in the <code>splitLine</code> array.  My SSCCE attempt at this is as follows:</p>
  
  <pre><code>    String line = "6 + 5 + 6  3 + 18";
      String regex = "(?&lt;=[-+*/()])|(?=[-+*/()])";   //Not spitting 6 3 correctly
      String[] splitLine = line.split(regex);
      for (int i=0; i&lt;splitLine.length; i++) {
          System.out.println(splitLine[i]);
      }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>6
  +
  5
  +
  6  3 //Error here
  +
  18
  </code></pre>
  
  <p>Expected Output:</p>
  
  <pre><code>6
  +
  5
  +
  6    //Notice
  3    //these
  +
  18
  </code></pre>
  
  <p>I've tried and tried to modify my regex expression and have been unsuccessful. Could anyone tell me why my regex expression isn't splitting the <code>6</code> and the <code>3</code> into their own <code>Strings</code> in the <code>splitLine</code> array? </p>
  
  <p><strong>Edit:</strong> Just wanted to point out that I am doing this for fun, it is not for any sort of school work, etc. I just wanted to see if I could write a program to perform simple infix expressions. I do agree that there are better ways to do this and if the expression were to become more complicated I would run into some issue. But unfortunately this is how my book recommended I approach this step.</p>
  
  <p>Thanks again for all of the quick comments and answers!</p>