Regex for balanced brackets?

From: Date: Mon, 21 Nov 2005 19:42:46 +0000
Subject: Regex for balanced brackets?
Groups: php.general 
Request: Send a blank email to php-general+get-226237@lists.php.net to get a copy of this message
I came across this method of matching brackets with regex in .NET http://puzzleware.net/blogs/archive/2005/08/13/22.aspx but I am wondering if it is possible to do the same in PHP? I've tried it a bit but I can't seem to get it to work properly. I'm just wondering if I am doing something wrong or if it is just not possible. Thanks. here is the code I was playing with: <?php $pattern = <<<PATTERN \{ (?> [^{}]+ | \{ (?P<DEPTH>) | \} (?P<-DEPTH>) )* (?(DEPTH)(?!)) \} PATTERN; $subject = <<<SUBJECT test { test2 { test3 } } test4 { } SUBJECT; preg_match_all("/$pattern/ix",$subject,$matches); header("content-type: text/plain; "); var_dump($matches); ?> - Jeff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Jeffrey Sambells Director of Research and Development Zend Certified Engineer (ZCE) We-Create Inc. jeff@wecreate.com email 519.745.7374 office 519.897.2552 mobile ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get Mozilla Firefox at http://spreadfirefox.com

« previous php.general (#226237) next »