PHP preg_match_all:按第一个字符拆分字符串


php's preg_match_all: split string by first character

我想使用 PHP 的 preg_match_all 函数通过某个字符来拆分字符串,而"特定字符"是字符串中的第一个字符,例如:

$pattern = '/#(?P<word>[.....])';
$string = 'one#two#three';
$matches = array();
preg_match_all($pattern,$string, $matches);
// expected $matches array: $matches['word'] = 'one','two','three'

因此,"拆分字段字符"本身就是模式的一部分(第一个字符)。

这可能吗?如果是,如何?

为什么不使用爆炸?

$matches = explode('#', $string);