Php 用正则表达式解析字符串

Php 用正则表达式解析字符串,php,regex,Php,Regex,我正在尝试分析此字符串: $right = '34601)S(1,6)[2] - 34601)(11)[2] + 34601)(3)[2,4]'; 使用以下regexp: const word = '(\d{3}\d{2}\)S{0,1}\([^\)]*\)S{0,1}\[[^\]]*\])'; preg_match('/'.word.'{1}(?:\s{1}([+-]{1})\s{1}'.word.'){0,}/', $right, $matches); print_r($matches);

我正在尝试分析此字符串:

$right = '34601)S(1,6)[2] - 34601)(11)[2] + 34601)(3)[2,4]';
使用以下regexp:

const word = '(\d{3}\d{2}\)S{0,1}\([^\)]*\)S{0,1}\[[^\]]*\])';
preg_match('/'.word.'{1}(?:\s{1}([+-]{1})\s{1}'.word.'){0,}/', $right, $matches);
print_r($matches);
我想返回如下数组:

Array
(
    [0] => 34601)S(1,6)[2] - 34601)(11)[2] + 34601)(3)[2,4]
    [1] => 34601)S(1,6)[2]
    [2] => -
    [3] => 34601)(11)[2]
    [4] => +
    [5] => 34601)(3)[2,4]
)
但我只返回以下内容:

Array
(
    [0] => 34601)S(1,6)[2] - 34601)(11)[2] + 34601)(3)[2,4]
    [1] => 34601)S(1,6)[2]
    [2] => +
    [3] => 34601)(3)[2,4]
)
我认为,这是因为[^]*或[^]]*在世界上, 但是我应该如何更正regexp以另一种方式匹配它呢

我试图具体说明:

\d+(?:[,#]\d+){0,}
所以这个词变成了

const word = '(\d{3}\d{2}\)S{0,1}\(\d+(?:[,#]\d+){0,}\)S{0,1}\[\d+(?:[,#]\d+){0,}\])';

但是它什么也没给。好吧,我用这个,它很有效

preg_match_all('/(?:\s{1}([+-]{1})\s{1}){0,}'.word.'/', $right, $matches);

好的,我使用这个,它在匹配所有('/(?:\s{1}([+-]{1})\s{1}){0,}.word'/',$right,$matches)之前工作;因此,它与这个preg_match_all('/(?:\s{1}([+-]{1})\s{1}){0,}.word.'/',$right,$matches)一起工作;还有一个问题,我可以用preg\u match匹配第一个单词后出现的所有单词,还是必须使用preg\u match\u all?