 <p><strong>Try with following regex:</strong></p> <pre><code>(?:^|[^\^])((?:\- *)?\d+) </code></pre> <p>Combine it with <a href="http://php.net/manual/en/function.preg-match-all.php" rel="nofollow"><code>preg_match_all</code></a> function.</p> <p><strong>Explanation:</strong></p> <p>It matches all digits</p> <pre><code>(\d+) </code></pre> <p>with optional negative sign (whitespacesbetween allowed)</p> <pre><code>(?:\- *)? </code></pre> <p>that are not followed with <code>^</code> sign</p> <pre><code>[^\^] </code></pre> <p>or are on the beggining of the string</p> <pre><code>^ </code></pre> <p>(so there is <code>^|[^\^]</code>) matched in non-captured group</p> <pre><code>(?:^|[^\^]) </code></pre>