note 31152 deleted from function.preg-match-all by sniper

From: Date: Tue, 30 Sep 2003 12:23:16 +0000
Subject: note 31152 deleted from function.preg-match-all by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57437@lists.php.net to get a copy of this message
Note Submitter: remcoman@hotmail.com ---- Here's a regular expression to match html attributes made by me for an template class.... '/([a-zA-Z0-9]+)[\s]{0,1}=[\s]{0,1}((\')|"|)((?: (?:\\\\\\2)|(?(3)[^\']|[^"]))*)(\2)(?:\s|$)/U' (don't forget to put it on one line!!!) use it like this.... $str = 'attrName="attrV\"alue2" attrName=attrValue2 attrName=\'attr\\\'Value3\' '; //all on one line!!!! $regexp = '/([a-zA-Z0-9]+)[\s]{0,1}=[\s]{0,1}((\')|"|) ((?:(?:\\\\\\2)|(?(3)[^\']|[^"]))*)(\2)(?:\s|$)/U'; preg_match_all($regexp,$str,$matches,PREG_SET_ORDER); print_r($matches); ......will output Array ( [0] => Array ( [0] => attrName1="attrV\"alue2" [1] => attrName1 [2] => " [3] => [4] => attrV\"alue2 [5] => " ) [1] => Array ( [0] => attrName2=attrValue2 [1] => attrName2 [2] => [3] => [4] => attrValue2 [5] => ) [2] => Array ( [0] => attrName3='attr\'Value3' [1] => attrName3 [2] => ' [3] => ' [4] => attr\'Value3 [5] => ' ) ) p.s. Oostzaan rules ;-P

« previous php.notes (#57437) next »