Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

( #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? 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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2014-07-14 00:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (252 votes), past polls