Tuesday, 15 September 2015

regex - PHP: preg_match_all that matches inner brackets first? -



regex - PHP: preg_match_all that matches inner brackets first? -

in php have string nested brackets:

bar[foo[test[abc][def]]bar]foo

i need regex matches inner bracket-pairs first, order in preg_match_all finds matching bracket-pairs should be:

[abc] [def] [test[abc][def]] [foo[test[abc][def]]bar]

all texts may vary.

is possible preg_match_all ?

this not possible regular expressions. no matter how complex regex, homecoming left-most match first.

at best, you'd have utilize multiple regexes, you're going have problem because regexes can't count matching brackets. best bet parse string other way.

php regex preg-match-all

No comments:

Post a Comment