Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: tag a matched text

by Samy_rio (Vicar)
on Apr 16, 2007 at 11:58 UTC ( #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
Node Status?
node history
Node Type: note [id://610325]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2020-05-29 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (169 votes). Check out past polls.

    Notices?