小编Xov*_*ver的帖子

计算开始的空格

我想计算(在单个正则表达式中)字符串开头的所有空格.

我的想法:

$identSize = preg_match_all("/^( )[^ ]/", $line, $matches);
Run Code Online (Sandbox Code Playgroud)

例如:

$example1 = " Foo"; // should return 1
$example2 = "  Bar"; // should return 2
$example3 = "   Foo bar"; // should return 3, not 4!
Run Code Online (Sandbox Code Playgroud)

任何提示,我如何解决它?

php regex

8
推荐指数
2
解决办法
3003
查看次数

标签 统计

php ×1

regex ×1