About regular expression question

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top