in reply to Replacing the pattern

Hello Everyone, I am having a problem which is pinching me again and again. I have tried each and every method that I can think for but of no vain. I hope that u can help me out. The following is just an abstract of the document where the particular pattern can be found many a times. And also there is not any specific location where that <page> or its no. (here 2) is found. I mean to say that there can be any spaces or lines before ,in or after the pattern found. My Data is suppose this
</TABLE> 2 <PAGE> RISK/RETURN SUMMARY AND FUND EXPENSES PRIME MONEY MARKET FUND
It should be converted to
</TABLE> RISK/RETURN SUMMARY AND FUND EXPENSES PRIME MONEY MARKET FUND
Hope that it provides u a better look.

Edit by castaway - reparented under original question

Replies are listed 'Best First'.
Re: The same pattern searching
by sasikumar (Monk) on Jan 21, 2005 at 07:32 UTC
    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
      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.