python vs. grep
Ricardo Aráoz
ricaraoz at gmail.com
Mon May 12 10:03:08 EDT 2008
Ville Vainio wrote:
> On May 8, 8:11 pm, Ricardo Aráoz <ricar... at gmail.com> wrote:
>
>> All these examples assume your regular expression will not span multiple
>> lines, but this can easily be the case. How would you process the file
>> with regular expressions that span multiple lines?
>
> re.findall/ finditer, as I said earlier.
>
Hi, sorry took so long to answer. Too much work.
findall/finditer do not address the issue, they merely find ALL the
matches in a STRING. But if you keep reading the files a line at a time
(as most examples given in this thread do) then you are STILL in trouble
when a regular expression spans multiple lines.
The easy/simple (too easy/simple?) way I see out of it is to read THE
WHOLE file into memory and don't worry. But what if the file is too
heavy? So I was wondering if there is any other way out of it. Does grep
read the whole file into memory? Does it ONLY process a line at a time?
More information about the Python-list
mailing list