LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Excluding text in Perl (https://www.linuxquestions.org/questions/programming-9/excluding-text-in-perl-447651/)

rigel_kent 05-23-2006 05:56 AM

Excluding text in Perl
 
Good morning,

I have a variable, $data, wich contains text (with lines, paragraphs, etc.).

How can I exclude a portion of the text beggining with some words and ending at another?

I've triesd:

Code:

$data =~ s/First words(.*|\r|\n)last words//gmi;
but it doesn't work.

Any ideas?

Regards,

Rigel_Kent

acid_kewpie 05-23-2006 06:09 AM

well i'd suggest takign the two parts either side and joining them together afterwards.

$data =~ /^(.*)start.*end(.*)$/;
echo $1 . $2;

should work ok save for my probable syntax errors.

spirit receiver 05-23-2006 07:25 AM

try
Code:

$data =~ s/First words.*?last words//gsi;
(I guess it's the /s-modifier you were looking for, and note the non-greedy *?)

rigel_kent 05-23-2006 08:35 AM

Doesn't work...it should.

Regards,

Rigel Kent

rigel_kent 05-23-2006 08:56 AM

Correction: it works !!!

Thanks,

Rigel_Kent


All times are GMT -5. The time now is 06:52 PM.