About regular expression question

Discussion in 'Perl Misc' started by sonet, May 13, 2007.

  1. sonet

    sonet Guest

    The $str is the xml string.
    <a>
    <c>123</c>
    <d>abc</d>
    </a> <b/> ...

    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?
    sonet, May 13, 2007
    #1
    1. Advertising

  2. On Sun, 13 May 2007 14:37:53 +0800, "sonet" <>
    wrote:

    >Subject: About regular expression question

    [snip]
    >The $str is the xml string.


    Use some XML parsing module.


    Michele, who is not reading further
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, May 13, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Munn

    Regular expression question...

    Andrew Munn, Jun 29, 2003, in forum: Perl
    Replies:
    1
    Views:
    2,109
    rakesh sharma
    Jun 30, 2003
  2. Glenn Kidd

    Regular expression question

    Glenn Kidd, Aug 18, 2003, in forum: Perl
    Replies:
    0
    Views:
    921
    Glenn Kidd
    Aug 18, 2003
  3. VSK
    Replies:
    2
    Views:
    2,272
  4. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    832
    Alan Moore
    Dec 2, 2005
  5. GIMME
    Replies:
    3
    Views:
    11,924
    vforvikash
    Dec 29, 2008
Loading...

Share This Page