a slight variation on Corion's proposal, tested here at the command line:
Edit: My computer froze when I was about to post this. I had to reboot. When I could start again to post, I did not notice that Eily had posted another solution fixing Corion's initial attempt.$ perl -e 'use strict; > use warnings; > use Data::Dumper; > > my $string = <<STR; STR> > SECTION 1 > > This is section 1 > > SECTION 2 > > This is section 2 > > STR > > > my %values = ($string =~ /(SECTION \d+)\s+([\w ]+)/mg); > print Dumper \%values; > ' $VAR1 = { 'SECTION 2' => 'This is section 2', 'SECTION 1' => 'This is section 1' };
In reply to Re: Regex to array
by Laurent_R
in thread Regex to array
by kepler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |