[yunqa.de] Re: [DIRegEx] How to Best do Multiple Find and Replace in File(s)?

Randy Carr wrote:

I believe that the search/replace process you descibed is already quite 
optimal. I took care to optimize TDIPerlRegEx so it studies the pattern 
automatically, which tends to speed up searching for larger strings like your. 
Replace2 should also be speedy as it works around the default string 
reallocation, which can be quite slow.

Depending on the number of files you are processing, you might consider to set 
up multiple TDIRegEx instances in advance so you need to compile each pattern 
only once.

Other than that, all you can do is to write faster your regular expression 
patterns. In particular, avoid backtracking patterns if possible and use atomic 
grouping instead. This is explained in more detail in the "Syntax Details" help 
page, "Atomic Grouping and Possessive Quantifiers" section.

Ralf

>I'd like to get your opinion on the best way to use DIRegEx to make
>multiple search AND replace passes on moderate sized (200-800K) text
>files?
>
>I'm doing some reformatting/converting of files. So, for each file, I
>might have 20-50 different RegEx patterns to search for, and each search
>pattern will have a corresponding replace pattern. The search patterns
>may be fairly complex, involving pattern captures, case sensitivity, and
>multiple lines.
>
>I'm planning on reading a file into memory as a String, and then make
>multiple RegEx passes over that String. I'll then use the "Match" and
>"Replace2" functions to do the replacing since I'll likely want to
>replace all occurances. I'll then take the changed output of the
>Replace2, and re-execute the "SetSubjectStr" command before moving on to
>the next pair of Search/Replace strings. When done, I'll save back to a
>file, and then repeat this for as many files as I have.
>
>I think this will work, but is there a better (faster or more efficient)
>way to do this? How about for very large text files?

_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
http://www.freelists.org/list/yunqa



Other related posts: