My approach would be to read the file and split it into an array of words, then go through the array and detect matches. For each match you can print the subarray $words[$index-$pre .. $index+$post]. I think this is the sort of thing Ovid had in mind. Using modules is always easier than doing things yourself, but if your definition of words is imple enough, it may be not to onerous.
Of course, if the file is LARGE, you might want to only read sections of the file at a time, and update your 'window' when you have fewer than $post words left in memory.
The next problem is defining what is a word .... Wonder if Shakespeare had anything to say on the topic?
Tom--
TTTATCGGTCGTTATATAGATGTTTGCA
In reply to Re: Regex: Matching around a word(s)
by TomDLux
in thread Regex: Matching around a word(s)
by shotgunefx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |