LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-23-2006, 05:56 AM   #1
rigel_kent
Member
 
Registered: Nov 2004
Posts: 64

Rep: Reputation: 15
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
 
Old 05-23-2006, 06:09 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
Old 05-23-2006, 07:25 AM   #3
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
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 *?)

Last edited by spirit receiver; 05-23-2006 at 07:28 AM.
 
Old 05-23-2006, 08:35 AM   #4
rigel_kent
Member
 
Registered: Nov 2004
Posts: 64

Original Poster
Rep: Reputation: 15
Doesn't work...it should.

Regards,

Rigel Kent
 
Old 05-23-2006, 08:56 AM   #5
rigel_kent
Member
 
Registered: Nov 2004
Posts: 64

Original Poster
Rep: Reputation: 15
Correction: it works !!!

Thanks,

Rigel_Kent
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl text menu system toolshed Programming 3 04-26-2011 07:35 PM
perl question: text editing feetyouwell Programming 2 03-14-2005 02:19 PM
C++ or perl how to not display text when typing true_atlantis Programming 6 10-03-2004 12:35 AM
inputing text in perl rob0t Programming 3 08-03-2004 10:29 PM
italics and underlined text on PERL randomx Programming 2 03-15-2004 12:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration