"Recursion too deep" crashes v5
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
"Recursion too deep" crashes v5
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.
Can't remember it exactly, but it was something like:
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.
Code: Select all
^\(.+\)||\(.+\)||\(.+\)||\(.+\)||.+SOME TEXT.+$
The regex works most of the time but as I said it crashes on very long llines, about 15,000+ characters.
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
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.+$
In Posix syntax your regex is:
^(.+)\|\|(.+)\|\|(.+)\|\|(.+)\|\|.+SOME TEXT.+$
If there are no |s between the ||s, use this instead:
^([^|]+)\|\|([^|]+)\|\|([^|]+)\|\|([^|]+)\|\|.+SOME TEXT.+$
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:
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.
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
(.+?)\|\|(.+?) ...
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
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/).