in reply to The same pattern searching
in thread Replacing the pattern

Hi,

Is this solving your problem. It solves for the sample data you have posted

use strict; my $target_data="</TABLE>\n\n2\n<PAGE>\n\nRISK/RETURN SUMMARY AND FUND + EXPENSES\n\n\nPRIME MONEY MARKET FUND"; my $pattern='(\n\s*[0-9]{1,3}\s*\n\s*<page>\s*\n)(.*)(\n*)'; $target_data =~ s/$pattern/" " x length($1).$2."\n" x length($3)."\n" +x length($1)/gie; print $target_data; print "\n\n";


The output is

</TABLE> RISK/RETURN SUMMARY AND FUND EXPENSES PRIME MONEY MARKET FUND
If the "\n" looks too many then you can change my regx concatenation of the regx to minimize it
"\n" x length($3)."\n" x length($1)/gie;
Thanks
SasiKumar

Replies are listed 'Best First'.
Re^2: The same pattern searching
by agynr (Acolyte) on Jan 21, 2005 at 09:09 UTC
    Thanks Sasi but the above code doesn't solve my problem. As it is not the general problem for the all patterns found but it is just for the above example. As I had told earlier that the location of the pattern or the no. of lines in the pattern found is not fixed and there is no surity that the page no found could be only that way. The pattern found could be
    abc The pattern follows <page> 24 def
    Like for the above case the code will not work. I had tried this code before also. I had made the pattern for the above cases as
    $pattern='(\n\s*[0-9]{1,3}\s*\n\s*<page>\s*\n)'; if ($target_data =~ /$pattern/gi) { $target_data =~ s/$pattern/" " x length($1)." " x length($2)." " x len +gth($3)." " x length($4)/gie; } $pattern='(\n\s*-[0-9]{1,3}-\s*\n\s*<page>\s*\n)'; if ($target_data =~ /$pattern/gi) { $target_data =~ s/$pattern/" " x length($1)/gie; } $pattern='(\n\s*[A-Za-z]-[0-9]{1,3}\s*\n\s*<page>\s*\n)'; if ($target_data =~ /$pattern/gi) { $target_data =~ s/$pattern/" " x length($1)/gie; } $pattern='(\n\s*page\s*[0-9]{1,3}\s*of\s*[0-9]{1,3}\s*\n)'; if ($target_data =~ /$pattern/gi) { $target_data =~ s/$pattern/" " x length($1)/gie; }
    But the above patterns are just lacking in the counting the no. of lines if found in the data, that should be converted into spaces. I hope that now u have a clear picture of the problem.