Regular Expression Question
- From: "sonet" <sonet.all@xxxxxxxxxxxxx>
- Date: Sun, 13 May 2007 14:31:45 +0800
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?
.
- Follow-Ups:
- Re: Regular Expression Question
- From: numberwhun
- Re: Regular Expression Question
- Prev by Date: Re: How can I search and replace a string while preserving (not removing) trailing spaces?
- Next by Date: About regular expression question
- Previous by thread: Re: Regular Expression Question
- Next by thread: Re: Regular Expression Question
- Index(es):
Relevant Pages
|