PetreAdi has asked for the wisdom of the Perl Monks concerning the following question:
I have a file that looks like
aaa111bbb ab01ac d ab02ac ab03ac aaa222bbb ab04acab05ac r ab06ac aaa333bbb ab01ac t cab06acab10ac
I need to extract the number between 'aaa' and 'bbb' and then pick the following line and extract all numbers between 'ab' and 'ac'
Output would be:
111 01,02,03 222 04,05,06 333 01,06,10
My basic regex is:
use strict; use warnings; my $start = 'aaa'; my $end = 'bbb'; my $start1 = 'ab'; my $end1 = 'ac'; my @matches = $content =~ /${start}([0-9]{3})${end}.*?${start1}([0-9] +{2})${end1}/smg;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Extracting numbers from a text file
by haukex (Archbishop) on Nov 02, 2019 at 18:36 UTC | |
by PetreAdi (Sexton) on Nov 02, 2019 at 19:00 UTC | |
Re: Extracting numbers from a text file
by tybalt89 (Monsignor) on Nov 02, 2019 at 20:43 UTC | |
by PetreAdi (Sexton) on Nov 03, 2019 at 05:49 UTC | |
Re: Extracting numbers from a text file
by thanos1983 (Parson) on Nov 02, 2019 at 18:36 UTC | |
by PetreAdi (Sexton) on Nov 02, 2019 at 18:54 UTC |