How would I split this expression with regex?
<p>I'm working on solving an equation but I will like to use the constants to program my solution.</p>

<p>The method I'm working on is called decompose which decomposes the equation into constants. The problem is that when I split, an equation with a negative constant will yield an array with the absolute value of the constants. How can I achieve the minus sign while still using regex?</p>

<p>If the input is <code>ax+by=c</code>, the output should be <code>{a,b,c}</code>.</p>

<p>Helpful bonus: Is there a way to delete the empty elements that is created when I split. For example, if I type equation <code>2x+3y=6</code>, I end up with a "raw" array that contains the elements <code>{2,,3,,6}</code></p>

<p>Code:</p>

<pre><code>public static int[] decompose(String s)
{
    s = s.replaceAll(" ", "");

    String[] termRaw = s.split("\\D"); //Splits the equation into constants *and* empty spaces.
    ArrayList&lt;Integer&gt; constants = new ArrayList&lt;Integer&gt;(); //Values are placed into here if they are integers.
    for(int k = 0 ; k &lt; termRaw.length ; k++)
    {
        if(!(termRaw[k].equals("")))
        {
            constants.add(Integer.parseInt(termRaw[k]));
        }

    }
    int[] ans = new int[constants.size()];

    for(int k = 0 ; k &lt; constants.size(); k++) //ArrayList to int[]
    {
        ans[k] = constants.get(k);
    }
    return ans;
}
</code></pre>