I'm kinda wondering about this one. Since you know the structure
of the data (ie. the data starts after delimiter 'a' and ends with delimter 'b')
and you allow the key word to be a regular word in the data I would have to assume
your the $text in chromatics answer means that you have all the text in the same string.
As I recall, sorry I've lost my mastering regular expressions book, its in Japan with
Sawako, you need a regular expression that treats the newline charactor as an embeded charactor
rather than the end of a line.
/start(.*)end/s;
#rather than
/start(.*)end/;
#used like this
$file = 'C:\fixthis.txt';
open(SESAME, $file);
while(<SESAME>)
{
$text .= $_;
}
close(SESAME);
print $text;
$text=~/\n*$//;#get rid of trailing newlines
$text=~m/^start(.*)end$/s;
print $1;
########the file has this data ##########
# I inserted alot of the words start and end to test it.
#start
#this is the start house startthat jackstart built
#and i am end my fathers endchild
#all end good boys do finend
#and i eat end more chicken than any man that you have seen
#end
#############the out put is this#############
#this is the start house startthat jackstart built
#and i am end my fathers endchild
#all end good boys do finend
#and i eat end more chicken than any man that you have seen
That seems to work ok, if i understood the structure of your data correctly.
If not im sure you could modify the regular expression to fit your needs.
Remember, simple is better.
little_mistress@mainhall.com
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.