adrya407 has asked for the wisdom of the Perl Monks concerning the following question:
orunwanted_line1=blabla unwanted_line2=blabla my_variable=important_content_section1 important_content_section2 important_content_section3 unwanted_line3=blabla
I tryed the following regex:unwanted_line1=blabla unwanted_line2=blabla my_variable=important_content_section1 important_content_section2 important_content_section3 [stepxyz#xxxx]
important_content_section1 is never empty, that's why i used my_variable=.*\n but it does get what i want only if i got this:my ($getVariable) = $data =~ /(my_variable=.*\n(.+[^=]\n?)*)/;
What i want to get in $getVarible is:unwanted_line1=blabla unwanted_line2=blabla my_variable=important_content_section1 important_content_section2 important_content_section3 unwanted_line3=
Update: Based on anonymus monk response, i got the solution for first data format. This is the solution: my ($getVariable) = $data =~ /(my_variable=.*\n(?:[^=\n]*\n)*)/; How can i update the regex to stop also at the lines that match [step?my_variable=important_content_section1 important_content_section2 important_content_section3
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiline regex
by hippo (Archbishop) on Jun 22, 2016 at 12:27 UTC | |
by Eily (Monsignor) on Jun 22, 2016 at 12:31 UTC | |
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 | |
by Anonymous Monk on Jun 22, 2016 at 12:45 UTC | |
by Anonymous Monk on Jun 22, 2016 at 13:26 UTC | |
|
Re: Multiline regex
by Eily (Monsignor) on Jun 22, 2016 at 12:29 UTC | |
|
Re: Multiline regex (Updated!)
by haukex (Archbishop) on Jun 22, 2016 at 22:26 UTC | |
|
Re: Multiline regex
by Anonymous Monk on Jun 22, 2016 at 12:42 UTC | |
by adrya407 (Novice) on Jun 22, 2016 at 12:46 UTC | |
by adrya407 (Novice) on Jun 22, 2016 at 14:18 UTC | |
by Anonymous Monk on Jun 22, 2016 at 15:28 UTC | |
|
Re: Multiline regex
by kcott (Archbishop) on Jun 26, 2016 at 02:32 UTC |