"Recursion too deep" crashes v5

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
svivian
Posts: 10
Joined: Thu Mar 15, 2007 8:50 pm

"Recursion too deep" crashes v5

Post 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.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

What was the regular expression?
svivian
Posts: 10
Joined: Thu Mar 15, 2007 8:50 pm

Post 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.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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.+$
svivian
Posts: 10
Joined: Thu Mar 15, 2007 8:50 pm

Post 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.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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/).
Post Reply