in reply to Re: Regex to array
in thread Regex to array
It works if you add an end marker for the right part:
Edit: \s* rather than \s+ to allow empty section at EOFuse Data::Dump qw( pp ); my $str = <<_BLA_; SECTION 1 bla bla bla SECTION 2 blabla blabla SECTION 3 bla _BLA_ my %hash = $str =~ /(SECTION \d+)\s*(.*?)(?=SECTION|$)/sg; pp \%hash; __DATA__ { "SECTION 1" => "bla bla\nbla\n", "SECTION 2" => "blabla\nblabla\n", "SECTION 3" => "bla", }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Regex to array
by kepler (Scribe) on Jan 11, 2018 at 18:05 UTC |