regex - PHP : preg_match_all none xhtml attributes -
i want improve code not know how write regexp.
i want none xhtml attributes in tag.
so after preg match want :
array( 0 => "required", 1 => "autocomplete" );
$balise = <input id="myid" class="myclassa myclassb myclassc" required autocomplete/>;
i use preg_match_all("/(?<=\s)[\w]+(?=[\s\/>])/i", $balise, $attributs);
but regexp :
array( 0 => "myclassb", 1 => "required", 3 => "autocomplete" );
i not want myclassb
...
can me write regex ?
thx
you can add negative look-ahead (?![^=]*?")
make sure next " doesn't precede next =, way you're getting words aren't within quoted value. single-quote string " in regex won't terminate it.
preg_match_all('/(?<=\s)[\w]+(?=[\s\/>])(?![^=]*?")/i', $balise, $attributs);
Comments
Post a Comment