Page 1 of 1

RE Deleting Every Other Line Instead of Every Line

Posted: Tue Jul 30, 2013 1:11 am
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.

Posted: Tue Jul 30, 2013 4:12 am
by MudGuard

Code: Select all

^\t.*\n
works.

Posted: Tue Jul 30, 2013 4:52 pm
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.

Posted: Tue Jul 30, 2013 4:55 pm
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.

Posted: Thu Aug 01, 2013 9:24 pm
by kengrubb
Try this

Search, Clear All Bookmarks

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

Edit, Delete, Bookmarked Lines

Posted: Mon Aug 12, 2013 6:46 pm
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.

Posted: Tue Aug 13, 2013 2:07 am
by jeffy
ben_josephs wrote:So using (^)\t.*\n solves the problem.
Nice find.