std/boost regex_replace
returns modified string by value. In my case I have to search/replace by regex in a file. I have thousands of files to process and many of them are over 1MB in size. The string to be searched and replaced is rare (e.g. only 5-10% of files will have it).
So, with the available interface is that possible to run regex replace and if the searched string isn't found then avoid creating a copy of 1MB buffer?
I just don't seem to figure out, is that regex interface in c++ that failed that the only way is to first search for a string in my buffer and only if it's found then use regex_replace (effectively search for the second time)? Or can I reuse results from regex_match or regex_search and pass them to regex_replace?
Asked
Active
Viewed 267 times
0

Pavel P
- 15,789
- 11
- 79
- 128
-
It is possible to write the result of regex_replace straight to a file without creating an intermediate string. – n. m. could be an AI Nov 08 '16 at 06:55
-
@n.m. yes it is, but it's going to be extremely slow. fstream is slow... but that's not the point: not only I don't want to copy memory if there is no pattern in the file moreso i don't want to modify files that don't have that pattern :) – Pavel P Nov 08 '16 at 07:00
-
If you need to write it anyway, this isn't going to matter much. If you only need to write it if there was a replacement, just make a search first. Don't bother reusing its results, I/O will dominate any potential savings anyway. – n. m. could be an AI Nov 08 '16 at 07:32