Regular expression bug - lock up on blank line search

General questions about using TextPad

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

Post Reply
jbrady33
Posts: 6
Joined: Mon Apr 03, 2006 3:46 pm

Regular expression bug - lock up on blank line search

Post by jbrady33 »

latest version (8.1.1, 32 bit, windows 10)

doing a regex search and replace on blank lines , either
^\s*$
or
^$

both lock up the editor, forever spinning cursor. Only choice is to kill Textpad and lose changes.

Anyone else hit this?
User avatar
AmigoJack
Posts: 532
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

Can't reproduce this in 8.1.1x64 on Win7x64 - since you didn't wrote with what you're replacing your search matches it might indeed match itself endlessly. How about matching/replacing a line including its line end? As in

Code: Select all

^\s*$\n
(and replacing it with nothing)
jbrady33
Posts: 6
Joined: Mon Apr 03, 2006 3:46 pm

Post by jbrady33 »

the string you suggested seems to match lines that end with a blank (even if there is other text on the line.

I was looking for either lines that are just carriage returns or maybe with just white space - no other text.

I did confirm one part - if I do "find" on ^$ all is well, finds every line with nothing on it

If I do "replace" with the same search, replacing with nothing - forever spinning wait.

I used to do this in version 7 with no issues.

On a hunch I uninstalled the 32 bit version and installed 64, same result. Very weird, I must be cursed :)
jbrady33
Posts: 6
Joined: Mon Apr 03, 2006 3:46 pm

Post by jbrady33 »

CORRECTION: Your string didn't match lines with text, my error reading the highlighting.

I did sort of fix my issue though, by using ^\n to catch beginning and end of line together I avoid the lock up, and remove carriage return only line the way I wanted.

^\s*\n also removes blank lines with white spaces. Probably my mis-use of the $ end of line character

Thank You!
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

$ matches the end of a line, but not the newline (the character or characters that terminate the line); that is, it matches the empty string just before the newline.
\n matches a newline.
$\n is exactly equivalent to \n.

The problem with your regex replacement is that having matched a blank line (not including the newline) and replaced it with nothing, the cursor is at the end of the line. But your regex matches the empty string; so it matches again where it is, and replaces what it has matched (the empty string, nothing) with nothing. The cursor is now still at the end of the line, so it matches nothing again and replaces nothing with nothing again. And so ad infinitum.

TextPad might treat this situation in a repetitive replacement as a special case. When the regex has matched and the replacement made, if the regex would, without advancing, match the empty string at its current position, TextPad might advance the cursor, so that it doesn't loop endlessly. Unfortunately, it does not do this, so it does loop endlessly. You might regard this as undesirable behaviour.

The regex with a \n works because it doesn't match the empty string.

This may help to clarify what's going on:
https://forums.textpad.com/viewtopic.php?t=12864
But, there again, it may not!
Post Reply