in reply to Multiline regex
This looks to work for me on your sample data:
#!/usr/bin/env perl use strict; use warnings; my $data = 'unwanted_line1=blabla unwanted_line2=blabla my_variable=important_content_section1 important_content_section2 important_content_section3 unwanted_line3=blabla '; my ($getVariable) = $data =~ /(my_variable=.*)^\w+=/sm; print $getVariable;
Update: See Eily's first reply below. If unwanted_line3 is not the last unwanted line in the set after all, then you'll need a non-greedy grab on the capture group like so:
#!/usr/bin/env perl use strict; use warnings; my $data = 'unwanted_line1=blabla unwanted_line2=blabla my_variable=important_content_section1 important_content_section2 important_content_section3 unwanted_line3=blabla nonsense unwanted_line4=blabla whocansay '; my ($getVariable) = $data =~ /(my_variable=.*?)^\w+=/sm; print $getVariable;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multiline regex
by Eily (Monsignor) on Jun 22, 2016 at 12:31 UTC | |
|
Re^2: Multiline regex
by adrya407 (Novice) on Jun 22, 2016 at 12:39 UTC | |
by hippo (Archbishop) on Jun 22, 2016 at 12:47 UTC | |
by adrya407 (Novice) on Jun 22, 2016 at 13:08 UTC | |
|
Re^2: Multiline regex
by Anonymous Monk on Jun 22, 2016 at 12:45 UTC | |
|
Re^2: Multiline regex
by Anonymous Monk on Jun 22, 2016 at 13:26 UTC |