Wildones,
A couple thoughts. You really need to see an input string. One can't know if a regular expression works for a given source and target, without knowing the source format.
One thing you could do is comment out all of the replace instructions and send ChatLog out un-formatted, wrapped in a pre tag. You only need do this once -- you'll get an immediate picture of the source format.
Another way would just be to bring it up in debug, but for this you'd need a string your own brain can handle, so reduce the time interval to something small... 2 mins tops, depending how busy chat is.
The replace seems to me to be "eating" one leading character from the following line, and then adding the same timestamp & user id sequence after the linefeed, before the next user tag and before any remaining extraneous text. Maybe it is adding a username/timestmp to lines that don't have one, but I couldn't produce this behavior in the evaluator. My tests always end up with an extra user tag at the end, but our chat logs are nice and tidy. Anyway, have a look yourself - I plugged the actual arguments your replace call uses into the regexp evaluator Shinging Armor gave (thanks!):
https://regex101.com/r/tG1bS3/6
Once you know the format (either through debug or writing raw with a pre tag), fiddle with the input string in the regexp tool so that it matches the input format. To simulate attempts at successive passes through the while loop, copy the entire output window into the input window. I'm wondering if something could be causing it to stick in that while loop. We checked memory, but what about processor usage when it hangs?
Another thought is to rewrite that stuff to write the user messages into an array of strings, do an appropriate replace on each as well as the wiki-image/a-tag fixup replace, then use join() on the array to concat the strings into ChatLog (more efficient). I'd probably do this just on principle, but you'll likely have to rewrite or tweak the regexps and this won't spare you time in debug at first. If there's a performance problem though, this might fix it.