How to get count of substring in string using regular expressions?
<p>I have a string and format of substring, for example "Hello world!%1, abcdef%2, gfgf%14", i.e. format of substring is '%'+digit (0...infinity), and I need to get count of this substring in any string. I know about substring_count function, but for this function I need to know a defined line. So, please, tell me, how can I get count using regular expressions or anything else? </p>

<p>EDITED:</p>

<p>THis code works:</p>

<pre><code>$r = "Hello world!%1, abcdef%2, gfgf%14";

$matches = array();
preg_match_all('/\%\d+/', $r, $matches);
echo isset($matches[0]) ? count($matches[0]) : 0;
</code></pre>

<p>But if I have a space before %1 or after it, the code doesn't work. Please, fix this expression. Thanks in advance. </p>
