Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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.

Velusamy R.

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

Comment on Re: tag a matched text
Select or Download Code
Replies are listed 'Best First'.
Re^2: tag a matched text
by aakikce (Acolyte) on Apr 16, 2007 at 12:13 UTC

    Hi Velusamy,

    Many thanks for your reply

    Sorry. I think that I didn't give clear input. Can you please look at the following inputs:

    <surname>Coff</surname>, <givenname>D.,</givenname>, <surname>Coff</surname>, <givenname>D.,</givenname>

    <givenname>D.,</givenname>, <surname>Coff</surname>, <givenname>D.,</givenname>, <surname>Coff</surname>

    As per your coding, I will get incorrect result for the second line



Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2016-04-30 14:07 GMT
Find Nodes?
    Voting Booth?
    :nehw tseb si esrever ni gnitirW

    Results (441 votes). Check out past polls.