in reply to regex : get a paragraph, not just line

If your file is small enough (no more than several hundred meg and guaranteed not to grow beyond that size), slurping and searching the entire file may be useful. Code:

use warnings; use strict; my $doc = do { local $/; <DATA>; }; # slurp entire file # print "<<<$doc>>> \n"; # FOR DEBUG my $rx_account = qr{ (?<! \d) \d{12} (?! \d) }xms; my $rx_amount = qr{ (?<! \d) \d+ [.] \d\d (?! \d) }xms; my ($two_lines, $account, $amount) = $doc =~ m{ ( ^ ACCOUNT \s+ NUMBER \s+ ($rx_account) .*? ^ YOUR \s+ LOAN \s+ PAYMENT .*? ($rx_amount) ) }xms; print "two lines: <<<$two_lines>>> \n\n"; print "account '$account' amount '$amount' \n"; __DATA__ ACCOUNT NUMBER 000111111111 YOUR LOAN PAYMENT FOR THE YEAR WILL BE 00.00 OF WHICH 00.00 WILL BE FOR PRINCIPAL AND INTEREST, 00.00 WILL GO ESCROW ACCOUNT, AND .00 WILL BE FOR DISCRETIONARY ITEMS THAT YOU CHOSE TO BE INCLUDED WITH YOUR LOAN PAYMENT. THE EFFECTIVE DATE OF YOUR NEW SCHEDULED PAYMENT IS 00/00/00.
Output:
c:\@Work\Perl\monks\crusty_collins>perl match_multiline_1.pl two lines: <<<ACCOUNT NUMBER 000111111111 YOUR LOAN PAYMENT FOR THE YEAR WILL BE 00.00>>> account '000111111111' amount '00.00'

Updates:

  1. See also File::Slurp and friends.
  2. What you have shown in the OP is not what I would think of as a "paragraph" match, but rather a multi-line match. It's difficult to see from the given data just what a paragraph would be.


Give a man a fish:  <%-(-(-(-<