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;
In reply to Re: Multiline regex
by hippo
in thread Multiline regex
by adrya407
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |