title: Java Split Regex Names next to Symbols
body: <p>I am attempting to write an interpreter for a Backus Naur Form grammar. The following is the grammar:</p>
  <pre><code>&lt;statement&gt; ::= &lt;assignment&gt; | “PRINT” “(” &lt;expression&gt; “)”
  &lt;assignment&gt;    ::= &lt;variable&gt; = &lt;expression&gt;
  &lt;expression&gt;    ::= &lt;term&gt; &lt;expression*&gt;
  &lt;expression*&gt;   ::= “+” &lt;expression&gt; | “-” &lt;expression&gt; | “”
  &lt;term&gt;  ::= &lt;factor&gt; &lt;term*&gt;
  &lt;term*&gt; ::= “*” &lt;term&gt; | “/” &lt;term&gt; | “”
  &lt;factor&gt;    ::= &lt;number&gt; | &lt;variable&gt; | “(” &lt;expression&gt; “)”
  &lt;variable&gt;  ::= &lt;lowercase&gt; &lt;variable*&gt;
  &lt;variable*&gt; ::= &lt;variable&gt; | “”
  &lt;number&gt;    ::= &lt;digit&gt; &lt;number*&gt;
  &lt;number*&gt;   ::= &lt;number&gt; | “”
  </code></pre>
  <p>I am attempting to write the code that determines if a string is an expression. My idea is that I take the string and use the split function to get all of the separate words and symbols apart. I do that by doing something like this <code>String[] words = line.split(&quot;\\s+&quot;);</code></p>
  <p>When I do this, it will turn a string like <code>String line = &quot;y = x + 12 * z&quot;</code> into <code>String[] words = [&quot;y&quot;, &quot;=&quot;, &quot;x&quot;, &quot;+&quot;, &quot;12&quot;, &quot;z&quot;]</code>. This is not a problem for me. The problem arises, though, when I have an expression as such <code>String line = &quot;x=12+z&quot;</code> When I try and split this with my regex, it will give me <code>String[] words = [&quot;x=12+z&quot;]</code>. Is there any way that I can have a string split into words where it will make any of the following characters into their own words in the array: <code>+, -, *, /, =, (, )</code></p>
  <p>For example, if I have the string <code>String line = &quot;x = z+12 * y -(z *var )&quot;</code> it will become <code>String[] words = [&quot;x&quot;, &quot;=&quot;, &quot;z&quot;, &quot;+&quot;, &quot;12&quot;, &quot;*&quot;, &quot;y&quot;, &quot;-&quot;, &quot;(&quot;, &quot;z&quot;, &quot;*&quot;,&quot;var&quot;, &quot;)&quot;]</code></p>