James wrote:
Is there a way of writing a regex to find 1 or more occurances of specific text string, and replace with a single occurance.

e.g.:

<data tag>
AI000001
AI000001
AI000001
AI000001

needs to be replaced with <data tag>
AI0000001

thus (m/(AI\d{6}\n)/) will find one occurance and capture as $1 (assuming delimiter set to something other than \n, but how can this regex be modified to find multiple occurances and replace with a single occurance?


$ perl -le'
my $data = q[<data tag>
AI000001
AI000001
AI000001
AI000001
];
print $data;
$data =~ s/(AI\d{6}\n)(?=\1)//g;
print $data;
'
<data tag>
AI000001
AI000001
AI000001
AI000001

<data tag>
AI000001




John
--
use Perl;
program
fulfillment


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to