in reply to Matching range of text with another string in between
Welcome to the Monastery, periodicalcoder!
If the last line of each entry will always be CAS*, you can split up the file into chunks by setting the record separator ($/) to that, then configure your regex to match across newlines (/m) and to match newlines (/s). The zero-width lookahead (?:...) ensures that '00003' comes after "LX*" and before the record separator ("CAS*").
use warnings; use strict; open my $fh, '<', 'file.txt' or die $!; { local $/ = 'CAS*'; while (<$fh>){ print $_ if /LX\*.*(?=00003$)/ms; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching range of text with another string in between
by GrandFather (Saint) on Apr 22, 2016 at 03:30 UTC | |
by periodicalcoder (Novice) on Apr 22, 2016 at 17:44 UTC | |
by Anonymous Monk on Apr 22, 2016 at 18:11 UTC | |
by periodicalcoder (Novice) on Apr 22, 2016 at 19:28 UTC | |
by Anonymous Monk on Apr 22, 2016 at 19:35 UTC |