![]() |
|
#1
|
|||
|
|||
Regexing files without memory problemsHey all,
I'm making a few programs that do some regex work with files. Currently, the program loops through an array created by readlines(). Then, it "regexes" each line. The problem is, this wont catch the pattern I'm searching for if it spans multiple lines. (Example: I'm searching for "cows" but the file contains co\nws). One solution would be to read the ENTIRE file into memory, but that could eat up resources on a large scale. Does anyone have an idea for performing "cross-lines regex" without memory problems? Thanks a bunch, StalePretzel |
|||
|
#2
|
||||
|
||||
Re: Regexing files without memory problemsIs the file formatted in such a way that you can read in a group of arbitrary lines, e.g. like a paragraph at a time? That way you don't have to read the whole file but you will still ensure all line spans are caught.
Alternatively you could just load into memory a set amount of data, e.g. 15KB, which will ensure you don't exceed your memory requirements. I don't know if this may lead to a missed span but it may worth a try. __________________
Start Programming with Python-A beginner's guide to programming and the Python language. ------------- Common Sense v2.0-Striving to make the world a little bit smarter. |
|
#3
|
|||
|
|||
Re: Regexing files without memory problemsWell you could always read the file with the read() method (which takes a size in bytes as an argument, and returns that information as a string) to get a whole "paragraph", and then apply the regex changes to another file.
But seriously, most computers today have enough memory to read very big files, those have to be quite heavy if you doubt on editing them as a whole. regards (six months later...) |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A Few Tips on Buying Good Memory Cards and other Hi-Tech Electronic Accessories | haulkook | Computer Hardware Forum | 0 | 02-Jun-2008 04:53 |
| Hard drive/CPU Diagnoses Issues | binarybug | Computer Hardware Forum | 1 | 22-Jan-2007 20:23 |
| out of memory problems | pixienick | MS Visual C++ / MFC Forum | 1 | 25-Apr-2006 13:37 |
| Bloodshed Dev C++ Project Options | JdS | C++ Forum | 6 | 11-Nov-2005 18:23 |
| [Tutorial] Pointers in C (Part I) | Stack Overflow | C Programming Language | 1 | 08-Apr-2005 19:35 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The