RE Deleting Every Other Line Instead of Every Line

General questions about using TextPad

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

Post Reply
dougwong55
Posts: 13
Joined: Tue Feb 15, 2005 1:00 am

RE Deleting Every Other Line Instead of Every Line

Post by dougwong55 »

I'm using TextPad 7.0.9.

I want to delete lines that begin with a tab. My RE is deleting every other line instead of every line. What's bothering me is that it works when I step through the text deleting each line by line. It doesn't work when I do replace all. My file is too large to replace each line by itself. In my example I'm using <tab> to represent a tab character:

example:
<tab>1<tab><tab><tab>
<tab>2<tab><tab><tab>
<tab>3<tab><tab><tab>
<tab>4<tab><tab><tab>

result:
<tab>2<tab><tab><tab>
<tab>4<tab><tab><tab>

Find: ^\t[^\r]*\R
Replace with: null

I've tried almost every combination of \r\n, just \n, \R, or $ at the end of the RE and in the character class. They all give the same result. Thanks in advance.
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

Code: Select all

^\t.*\n
works.
dougwong55
Posts: 13
Joined: Tue Feb 15, 2005 1:00 am

Post by dougwong55 »

I just tried that. It didn't work. I got the same result as in my example. Thanks anyway.

I'm using Win7 32-bit. This is a company machine, so I can't switch to 64-bit.
dougwong55
Posts: 13
Joined: Tue Feb 15, 2005 1:00 am

Post by dougwong55 »

Sorry, I forgot to mention this.

When I replace the lines one by one, it works. When I replace all it doesn't work. The file is a large file and single replacement would take a long time.
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Post by kengrubb »

Try this

Search, Clear All Bookmarks

Find dialog
Find what: ^\t
Regular expression: checked
Mark All

Edit, Delete, Bookmarked Lines
(2[Bb]|[^2].|.[^Bb])

That is the question.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

The simpler regex suggested by MudGuard should work: the [^\r] (as opposed to a simple dot) in the original regex is unnecessary.

But neither of these regexes does work. When running a Replace All, replacing anything like ^.*\n with nothing, the recogniser misses out every other line. It seems that it fails to match ^ at the beginning of a line when it has just removed the preceding newline. This is a bug. Strangely, however, parenthesising the ^ seems to fix the problem.

So using (^)\t.*\n solves the problem.
User avatar
jeffy
Posts: 323
Joined: Mon Mar 03, 2003 9:04 am
Location: Philadelphia

Post by jeffy »

ben_josephs wrote:So using (^)\t.*\n solves the problem.
Nice find.
Post Reply