Hellbent wrote: ↑24 Jun 2021, 16:39
Do you have a estimate on how much faster your method is to the StrReplace() in this case?
No. The algos are completely different, and it depends strongly on the data (how many alternatives, how many matches, etc...). Regex may be even slower than a GOOD handcrafted parsing algo. The reason for using regex is not that it saves computing time, the reason is it tremendously saves programming time (and even if it's a little slower, in most cases that will be irrelevant). You don't have to program an algorithm for parsing your text, you just describe the patterns and call regexmatch/regexpreplace (of course, if the pattern consists of a single string, using regex does not make sense, you should use instr/strreplace in that case). This thread with a very simple task is a good example: You started off with strsplit, then, as you saw this as a dead end, you switched to strreplace and completely rewrote the code. But what if you want to replace whole words only, but allow all kinds of delimiters? Again, you wil have to completely rewrite your algorithm (and it's going to become complicated). Using regex, you always leave the program structure as it is and just adapt the regex that describes the pattern.
Hellbent wrote: ↑24 Jun 2021, 16:39
I don't know anything about RegEX, but aren't you basically just doing this in this case?
Doing what, precisely?
This looks a lot like a loop.
What am I missing here?
Where do you see a loop? In this script, there is one single regexreplace call, no loop. Of course, internally, in a program virtually everything happens in loops - regexreplace loops through the data, just as strreplace does, and as most other AHK commands and functions do.
Note: In an interpretive language like AHK, the speed gain of regex is probably bigger (or the speed loss is smaller) than in a compiled language, as there is some overhead for every script line executed.