I need to match all 'tags' (e.g.
%thisIsATag%) that occur within XML attributes. (Note: I'm guaranteed to receive valid
XML, so there is no need to use full DOM traversal). My regex is working, except when
there are two tags in a single attribute, only the last one
is returned.
In other words, this regex should
find tag1, tag2, ..., tag6. However, it omits tag2 and
tag5.
Here's a fun little test harness for you
(PHP):
$xml
= <<
height="250">
x="30%" y="50%" animatefromx="800">
fontstyle="bold" text="Screen One!%tag2% %tag3%"/>
delay='%tag4%'>
fontstyle="bold" text="Screen Tres!"/>
animatefromx="800">
XML;
$matches
=
null;
preg_match_all('#<[^>]+("([^%>"]*%([^%>"]+)%[^%>"]*)+"|\'([^%>\']*%([^%>\']+)%[^%>\']*)+\')[^>]*>#i',
$xml,
$matches);
print_r($matches);
?>
Thanks!
:)
No comments:
Post a Comment