Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Answer: How do I extract all text between two keywords like start and end?

by I0 (Priest)
on Mar 07, 2001 at 11:22 UTC ( #62683=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How do I extract all text between two keywords like start and end? - Answer contributed by I0

$_ = "start this is the start this is another end first end start hell +o start inside of hello end there end"; ($re=$_)=~s/((\bstart\b)|(\bend\b)|.)/${[')','']}[!$3]\Q$1\E${['(',''] +}[!$2]/gs; @$ = (eval{/$re/},$@); print join"\n",@$ unless $$[-1]=~/unmatched/;

  • Comment on Answer: How do I extract all text between two keywords like start and end?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[james28909]: how can i write a while loop on one line (in a script) something like print "this\n" && print "that" && <DATA> && print the other\n" && next if /this matches/ while <DATA>?
[james28909]: i have tried with && and and and have tried to rearrange the functions as well to no avail

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2018-05-20 18:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?