Hi, I've been having trouble extracting elements from XML-ish files using regular expressions. Say I want to extract all <dat1> elements from the following data:
<thing><dat1>This</dat1><dat2>is</dat2><dat1>a</dat1><dat3>bad</dat3><dat1>format</dat1></thing>
I use the code:
while ($thing =~ s/<dat1>.*?<\/dat1>/g) {
[do stuff with dat1 element]
}
I know, in the example above, I could use [^<]* but in some cases, there are nested tags in the elements I'm extracting, so I use .*?. However, for some reason, only the final element is located using this code. Is this a bug in Perl? (I'm using ActiveState Perl v5.8.3) Anyone else discovered this and found a good way around it? Thanks for all your time.
<thing><dat1>This</dat1><dat2>is</dat2><dat1>a</dat1><dat3>bad</dat3><dat1>format</dat1></thing>
I use the code:
while ($thing =~ s/<dat1>.*?<\/dat1>/g) {
[do stuff with dat1 element]
}
I know, in the example above, I could use [^<]* but in some cases, there are nested tags in the elements I'm extracting, so I use .*?. However, for some reason, only the final element is located using this code. Is this a bug in Perl? (I'm using ActiveState Perl v5.8.3) Anyone else discovered this and found a good way around it? Thanks for all your time.