I gave up. I am using PHP to match capture all [A-Za-z0-9-.]{1,7} inside EITHER parenthesis or square brackets.
I have the following reg expresion
$pattern = /(?:(?:\(|\[)([A-Za-z0-9-.]{1,7})(?:\)|\]))/
I cannot understand, why
$r->filename = Flood Control Geo Survey (Bali) (Indo) (2005) (V1.0) [acc].doc
if (preg_match($pattern, $r->filename, $matches)) {
echo $r->filename, '<br />';
echo '<pre>', var_dump($matches), '</pre><hr />';
}
Outputs:
array(2) {
[0]=>
string(6) "(Bali)"
[1]=>
string(4) "Bali"
}
I cannot understand why
[0]captured the opening parenthesis and closing parenthesis when my capture group is AFTER its declaration.[1]is correct and what I need, why i still have[0]?Why is it stopping?, there's still
(Indo),(2005),(V1.0)and[acc]? Why are those not captured?My desired output is:
array() { [0]=> string(6) "Bali" [1]=> string(4) "Indo" [2]=> string(4) "2005" [3]=> string(4) "V1.0" [4]=> string(4) "acc" }
Can somebody please help? Thank you!