Re[2]: [PHP-DEV] preg_match_all() weirdness

From: Date: Sun, 30 Dec 2001 14:05:59 +0000
Subject: Re[2]: [PHP-DEV] preg_match_all() weirdness
References: 1 2 3  Groups: php.dev 
Request: Send a blank email to php-dev+get-75353@lists.php.net to get a copy of this message
Hi, > Daniel Lorch wrote: >> shouldn't this be >> [^>]+ instead of [^]]+ > This yields the same result. because nothing matches the whitespace character, and foo is also not matched. i would suggest following regular expression: --- snip ---------------------------------------- <pre> <?php preg_match_all("'([^ ]+) *= *\"?([^\" >]*)\"? *'im", '<php:foo var1="value1" var2="value2" />', $matches ); parray_tree($matches); ?> </pre> --- snip ---------------------------------------- which yields this result: --- snip ---------------------------------------- |-+ 0 (array) | |-> 0 = "var1="value1" " (string) | |-> 1 = "var2="value2" " (string) |-+ 1 (array) | |-> 0 = "var1" (string) | |-> 1 = "var2" (string) |-+ 2 (array) | |-> 0 = "value1" (string) | |-> 1 = "value2" (string) --- snip ---------------------------------------- this will also match non-regular syntaxes such as var1 = value1 var1 = "value1" but is still somewhat buggy, because this isn't matched: var1="value1 blub" maybe you find a better method. the "Back references" which are needed to accomplish this (as described in the manual) don't seem to work (bug?). any regular expression GOD around here? btw: you don't have to escape characters like >. also, try to use other regular expression-delimitors instead of /../ if you use the slash frequently in the expression. Kind Regards, Daniel Lorch -- if(empty($a) == true ? true : false)

« previous php.dev (#75353) next »