Regular expression with match for subpattern
Posted: Thu Sep 11, 2008 5:33 am
Hi Everyone,
I've got the following code
which results in:
It returns the last match of every subpattern. What I wanted to achieve is getting al the possible matches, something like:
Is this possible and could you tell me how?
thanks in advance.
I've got the following code
Code: Select all
<?php
$key = 'S,M,L,XL-A/B,C/D';
if(preg_match_all("#((\w{1,2}),?)+-((\w/\w),?)+#", $key, $matches)){
echo '<pre>';
print_r($matches);
}
?>
Code: Select all
Array
(
[0] => Array
(
[0] => S,M,L,XL-A/B,C/D
)
[1] => Array
(
[0] => XL
)
[2] => Array
(
[0] => XL
)
[3] => Array
(
[0] => C/D
)
[4] => Array
(
[0] => C/D
)
)
Code: Select all
Array
(
[0] => Array
(
[0] => S,M,L,XL-A/B,C/D
)
[1] => Array
(
[0] => S
[1] => M
[2] => L
[3] => XL
)
[2] => Array
(
[0] => S,
[1] => M,
[2] => L,
[3] => XL
)
[3] => Array
(
[0] => A/B
[1] => C/D
)
[4] => Array
(
[0] => A/B,
[1] => C/D
)
)
thanks in advance.