tags:

views:

34

answers:

1

I trying to parse this string:

$right = '34601)S(1,6)[2] - 34601)(11)[2] + 34601)(3)[2,4]';

with following 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);

i want to return array like this:

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]
)

but i return only following:

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]
)

i think, its becouse of [^)]* or [^]]* in the word, but how i should correct regexp for matching this in another way?

i tryied to specify it:

\d+(?:[,#]\d+){0,}

so word become

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

but it gives nothing

A: 

well, i use this, and it works

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