Regex bug in UNIX mode file?

General questions about using TextPad

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

Post Reply
jhg
Posts: 3
Joined: Wed Nov 04, 2009 9:50 pm

Regex bug in UNIX mode file?

Post by jhg »

The following regex should find the next line that is empty or contains one or more tabs and/or spaces:

^[ \t]*$

This works, but when in UNIX mode and you hit a completely empty line (containing no spaces, tabs or other characters), you cannot advance past it hitting "Find Next". You have to manually move the line cursor down a line, at which point you can advance to the next matching line with "Find Next". This is 100% repeatable.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

This is not a bug and it has nothing to do with Unix or Windows line endings.

Your regex matches the empty string at the beginning of a line, followed by a (possibly empty) string of spaces or tabs, followed by the empty string at the end of a line. After a match is found the cursor is positioned at the end of whatever was matched.

So, on an empty line, the regex matches the empty string at the beginning of the line, followed by an empty string of spaces or tabs, followed by the empty string at the end of the line. That is, it matches an empty string. If you repeat the search, the regex matches again where it is and the cursor doesn't move. If you want to be able to repeat the search without explicitly moving the cursor, you have to ensure that the cursor moves each time a match is found, for example, by including the newline at the end of the line: ^[ \t]*\n .

Note that if you Mark All with your regex, all the blank lines are marked.
Post Reply