Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: tag a matched text

by Samy_rio (Vicar)
on Apr 16, 2007 at 11:58 UTC ( [id://610325]=note: print w/replies, xml ) Need Help??


in reply to tag a matched text

Hi aakikce, try like this,

use strict; use warnings; my $content = do{local $/; <DATA>}; $content =~ s/(<surname>(?:(?:(?!<\/surname>).)*)<\/surname>\,?\s*<giv +enname>(?:(?:(?!<\/givenname>).)*)<\/givenname>)/<au>$1<\/au>/gsi; $content =~ s/(<\/givenname>\,\s*)<au>(\s*<surname>)/$1$2/gis; $content =~ s/(<\/givenname>\s*)<\/au>(\,\s*<surname>)/$1$2/gis; $content =~ s/(<givenname>(?:(?:(?!<\/givenname>).)*)<\/givenname>\,?\ +s*<surname>(?:(?:(?!<\/surname>).)*)<\/surname>)/<au>$1<\/au>/gsi; print $content; __DATA__ <surname>Coff</surname>, <givenname>D.,</givenname> et al., <givenname +>J.</givenname> <surname>Amat</surname> <surname>Coffman</surname>, < +givenname>D.D.,</givenname> <givenname>D.,</givenname>, <surname>Coff</surname> et al., <givenname +>J.</givenname> <surname>Amat</surname> <surname>Coffman</surname>, < +givenname>D.D.,</givenname> output: ------- <au><surname>Coff</surname>, <givenname>D.,</givenname></au>, <au><sur +name>Coff</surname>, <givenname>D.,</givenname></au> <au><givenname>D.,</givenname>, <surname>Coff</surname></au>, <au><giv +enname>D.,</givenname>, <surname>Coff</surname></au>

In your expected output, second line is same as input. I think it's typo.

Updated: aakikce, now you can try with your sample.

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://610325]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2025-11-16 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (72 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.