字符串中的模式搜索

时间:2021-07-19 14:56:19

标签: php regex string laravel-8

我有一个字符串,我想计算其中特定模式的出现次数。我使用 php 函数 substr_count()。

$string = PPPBBPPPTTTBBBBTBBBTTTTPBT;
$pattern = BB;
$count = substr_count($string, $pattern);

此返回计数为 4 但实际结果应为 1(因为我不想考虑 BBBB 我只想考虑 BB)

是否还有其他 php 函数可以过滤确切的模式?

0 个答案:

没有答案