legin has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to write a regex that extracts three lines from the following:
I'd like a regex that returns each logical line and ignores the embedded newlines. Something like:my $string = <<STRING; one. two \n \n . three. STRING
How can I write a regex that ignores the two embedded newline characters (see line two)?my @lines = $string =~ m/^(.*?)$/msg; # I need this test to pass is(scalar(@lines), 3, 'found 3 lines only');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: extracting lines from a string - while ignoring the \n character
by svenXY (Deacon) on Oct 29, 2007 at 09:33 UTC | |
|
Re: extracting lines from a string - while ignoring the \n character
by moritz (Cardinal) on Oct 29, 2007 at 09:50 UTC | |
|
Re: extracting lines from a string - while ignoring the \n character
by erroneousBollock (Curate) on Oct 29, 2007 at 09:31 UTC | |
by codeacrobat (Chaplain) on Oct 29, 2007 at 19:56 UTC | |
by erroneousBollock (Curate) on Oct 30, 2007 at 02:04 UTC | |
|
Re: extracting lines from a string - while ignoring the \n character
by Anonymous Monk on Oct 30, 2007 at 01:15 UTC |