我正在使用以下表达式查找 我希望它返回6 但它只返回 这是 有什么方法可以得到' code>和<的出现次数 代码>“ code>在一个字符串中我不希望计数包含
\' code>或
\” code>。 p>
$ subStr ='asdf“asdf”“a \\”sdf \'asdf \'\'a \\\'sdf';
npreg_match_all('/ [^ \\\\] \'| [^ \ \\\] \“/',$ subStr,$ matches);
echo count($ matches [0]);
code> pre>
4 code>。我认为这是因为字符串
“” code>和
'' code>只计算一次。 p>
$ matches code>包含: p>
Array
(
[0] =&gt; Array
(\ n [0] =&gt; f“
[1] =&gt; f”
[2] =&gt; f'
[3] =&gt; f'
)
)
< / code> pre>
6 code>的数量吗?注意我还需要排除
\“ code> 和
\' code>。 p>
div>
I'm using the following expression to find the number of occurences of '
and "
in a string I don't want the count to include \'
or \"
.
$subStr = 'asdf"asdf""a\\"sdf\'asdf\'\'a\\\'sdf';
preg_match_all('/[^\\\\]\'|[^\\\\]\"/', $subStr, $matches);
echo count($matches[0]);
I expect it to return 6 but it only returns 4
. I think this is because the strings ""
and ''
are only count once.
This is what $matches
contain:
Array
(
[0] => Array
(
[0] => f"
[1] => f"
[2] => f'
[3] => f'
)
)
Is there any way I can get the count of 6
? Note that I also need to exclude the \"
and \'
.