Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Find and replace using regex

by Samy_rio (Vicar)
on Jul 13, 2006 at 12:50 UTC ( [id://560932]=note: print w/replies, xml ) Need Help??


in reply to Find and replace using regex

Hi rsriram, Try this,

use strict; use warnings; my $data = do{local $/; <DATA>}; my $i = 1; while ($data =~ s/(<FN$i>(?:(?:(?!<\/FN$i>).)*)<\/FN$i>)\n*//gsi){ my $foot = $1; $data=~ s/<FN${i}ref>/$foot/gi; $i++; } print $data; __DATA__ This is my text<FN1ref>. This is my text This is my text. This is my text<FN2ref>. This is my text This is my text. This is my text<FN3ref>, this is my text This is my text. This is my text<FN4ref>, this is my text This is my text. This is my text<FN5ref>, this is my text This is my text. <FN1>Footnote1</FN1> <FN2>Footnote2</FN2> <FN3>Footnote3</FN3> <FN4>Footnote4</FN4> <FN5>Footnote5</FN5> Output: ------- This is my text<FN1>Footnote1</FN1>. This is my text This is my text. This is my text<FN2>Footnote2</FN2>. This is my text This is my text. This is my text<FN3>Footnote3</FN3>, this is my text This is my text. This is my text<FN4>Footnote4</FN4>, this is my text This is my text. This is my text<FN5>Footnote5</FN5>, this is my text This is my text.

Regards,
Velusamy R.


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found