Page 1 of 1

"Recursion too deep" crashes v5

Posted: Thu Sep 06, 2007 11:46 am
by svivian
Textpad 5 kept crashing when searching for a regular expression (that contained .+ several times). After going back to v4 (again...) the same thing happened, only it popped up an alert saying "Recursion too deep; Stack overflowed" or something like that. But I could carry on using the program. It seems to happen on lines that are longer than about 15,000 characters.

Posted: Thu Sep 06, 2007 1:17 pm
by ben_josephs
What was the regular expression?

Posted: Fri Sep 07, 2007 11:54 am
by svivian
Can't remember it exactly, but it was something like:

Code: Select all

^\(.+\)||\(.+\)||\(.+\)||\(.+\)||.+SOME TEXT.+$
It's from a text file I created to add data to a database, format is like FIELD||FIELD||FIELD||...

The regex works most of the time but as I said it crashes on very long llines, about 15,000+ characters.

Posted: Fri Sep 07, 2007 12:18 pm
by ben_josephs
That regex will cause a huge amount of back-tracking on long lines. Each .+ will match to the end of the line and then repeatedly back-track until it finds a || that allows a match to be found. Presumably something is overflowing in there.

In Posix syntax your regex is:
^(.+)\|\|(.+)\|\|(.+)\|\|(.+)\|\|.+SOME TEXT.+$

If there are no |s between the ||s, use this instead:
^([^|]+)\|\|([^|]+)\|\|([^|]+)\|\|([^|]+)\|\|.+SOME TEXT.+$

Posted: Sun Sep 09, 2007 10:37 pm
by svivian
Okay, thanks for that, worked well, and much more quickly, too.

BTW, is there a non-greedy operator when using the Posix mode? In many programming languages with regex support, you can do things like:

Code: Select all

(.+?)\|\|(.+?) ...
Which searches from the beginning and would stop at the first pipe, rather than searching all the way back from the end of the line.

Posted: Mon Sep 10, 2007 7:07 am
by ben_josephs
Unfortunately not. There's just one regex engine; it's just the syntax that's different. But non-greedy operators and many other goodies are available in Helios's other product, WildEdit (http://www.textpad.com/products/wildedit/). This is designed "to make the same changes to a set of text files in a folder hierarchy", and uses a far more powerful regular expression engine (Boost: http://www.boost.org/libs/regex/doc/).