Sounds like a classic case of the regexp engine doing backtracking.
The regexp engine searches forward until it matches the regexp. Then it begins searching backward from the end of the file, until the regexp matches as much as possible. Which in this case is only one character. This is called greedy matching.
So the first thing you can do is make the match lazy. Tell the regexp engine it's okay to do as little as possible. You do that by adding a ? after the repeat modifier.
\n+?
That says match 1 or more newlines, but don't knock yourself out.
The second thing you can do is make the regexp so the engine doesn't have to search backward.
\n[^\n]
So that says "match a newline followed by something that isn't a newline." When the regexp engine sees that it has matched the whole pattern to begin with, it stops. In experiments I just did, this was the fastest, even faster that the lazy modifier.
If you have blank lines in your file (\n followed by \n), you can use this regexp: \n+[^\n]
"Match one or more newlines, followed by a non-newline."
So it seems TextMate's regexp is working as it should.
Regards, JJ
On 16-Jan-2006, at 18:51, Tom Lazar wrote:
whoha!
I just wanted to do some xml-wrangling with TM and opened my usual accounting file which contains ca. 6000 lines of xml.
I work with it all the time and never experienced any problems. except for right now, when i did a search and replace with regular expressions, just simply remoing all line-breaks, ie. replacing '\n' with nothing.
TM has been maxing out the CPU for ten minutes now (Dual 1GHz G4) and doesn't let me do anything. I've got ca 15 projects open and am praying that they're saved.
How can this be avoided in the future? is TM really only usable for small files such as XHTML templates or code? that'd be a real shame...
can anybody shed any light on this or give some advice, what other product to use for the 'heavy lifting stuff'?
best regards,
tom
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
--- Help everyone. If you can't do that, then at least be nice.