I'm using PHP. Given, for example, the following string:
$str = "a2c4-8|a6c2,c3-5,c6[2],c8[4]-10,c14-21[5]|a30"
and exploding it by | I get the strings:
a2c4-8
a6c2,c3-5,c6[2],c8[4]-10,c14-21[5]
a30
Now I would like to separate the digits that follow the a from all the other characters, remove the letters a and c (keep dashes, commas and square brackets) and place the results in a multidimensional array as follows:
Array
(
[0] => Array
(
[a] => 2
[c] => 4-8
)
[1] => Array
(
[a] => 6
[c] => 2,3-5,6[2],8[4]-10,14-21[5]
)
[2] => Array
(
[a] => 30
[c] =>
)
)
a is always followed by digit and after this digit there may be or may not be a c followed by other comma separated strings.
Notice that in the resulting array the letters a and c have been removed. All other characters have been kept. I tried to modify this answer by Casimir et Hippolyte but without success.
A plus would be avoid to add to the resulting array empty array keys (as the last [c] above).