in reply to Regex: Matching around a word(s)
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex: Matching around a word(s)
by BrowserUk (Patriarch) on Dec 19, 2005 at 20:17 UTC | |
|
Re^2: Regex: Matching around a word(s)
by shotgunefx (Parson) on Dec 20, 2005 at 19:41 UTC |