Hi everyone:
Now I have a regular expressions with recursive pattern, here's my code:
$reg = '#
\(
(?P<outside>
(?P<inside>[^()]+)
|
(?R)
)*
\)
#x';
$m = preg_match_all($reg, '(first_part)(second_part(third_part))', $matches);
var_dump($matches);
The result:
array(3) {
[0]=>
array(2) {
[0]=>
string(12) "(first_part)"
[1]=>
string(25) "(second_part(third_part))"
}
["outside"]=>
array(2) {
[0]=>
string(10) "first_part"
[1]=>
string(12) "(third_part)"
}
["inside"]=>
array(2) {
[0]=>
string "first_part"
[1]=>
string "second_part"
}
}
How does the parser group this pattern?
I don't know why group #outside is "(third_part)" while matching "(second_part(third_part))".