note 34323 added to function.preg-match-all

From: Date: Wed, 23 Jul 2003 23:28:01 +0000
Subject: note 34323 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-52525@lists.php.net to get a copy of this message
In response to remcoman at hotmail dot com's post: I have slightly modified the regexp to work better in a couple ways: Original RegExp: /([a-zA-Z0-9]+)[\s]{0,1}=[\s]{0,1}((\')|"|) ((?:(?:\\\\\\2)|(?(3)[^\']|[^"]))*)(\2)(?:\s|$)/U RegExp: /([\w]+)(?:=((\')|"|)((?:(?:\\\\\\2)|(?(3)[^\']|[^"]))*) (\2))?(?:\s|$)/U The original will match: attr1="valu\"e 1" attr2=value2 attr3='valu\'\\\'e3' all the proper way one would expect. My slightly modified version also accepts: attr_1="valu\"e 1" attr2 Extra programming would have to be done for attributes with no '='. If there is no '=' for a given match, only the 1 match pattern will be returned (name of attribute). Otherwise, all 5? will be returned. -Percy PS: Make sure you put the RegExp on one line if you copy it. ---- Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34323 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34323&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34323&report=yes

« previous php.notes (#52525) next »