S
sonet
The $str is the xml string.
<a>
<c>123</c>
<d>abc</d>
</a> <b attr='456'/> ...
I need to detect some specific close tag.
ex:
(</a> or <a/>) OR (</b> or <b/>)
1.
if ($str=~/<\/(a|b)>|<(a|b)\/>/s){
#do something A;
}
2.
if ($str=~/<\/(a|b)>/s){
#do something A;
}elsif($str=~/<(a|b)\/>/s){
#do something A;
}
3.
if ($str=~/<\/(.*?)>|<(.*?)\/>/s){
if ($1 eq 'a' || $1 eq 'b'){
#do something A;
}
}
===========================================
Which one is the better? And have any more good RE
pattern for above example?
<a>
<c>123</c>
<d>abc</d>
</a> <b attr='456'/> ...
I need to detect some specific close tag.
ex:
(</a> or <a/>) OR (</b> or <b/>)
1.
if ($str=~/<\/(a|b)>|<(a|b)\/>/s){
#do something A;
}
2.
if ($str=~/<\/(a|b)>/s){
#do something A;
}elsif($str=~/<(a|b)\/>/s){
#do something A;
}
3.
if ($str=~/<\/(.*?)>|<(.*?)\/>/s){
if ($1 eq 'a' || $1 eq 'b'){
#do something A;
}
}
===========================================
Which one is the better? And have any more good RE
pattern for above example?