Using regular expressions to remove lines

General questions about using TextPad

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

Post Reply
Stefan

Using regular expressions to remove lines

Post by Stefan »

I want to use regular expressions to delete a full text line, but only the textlines which ends with a certain textstring.

for instance, I want to remove all lines endng with ".txt"

insert in the find and replace dialog:
find what: ".txt$"
replace with: ...

can anyone help me out?

Thanks
Stephan

Re: Using regular expressions to remove lines

Post by Stephan »

You could use search (check the regular expression check box), and then click 'Mark All' - CRTL-D B will then delete all marked lines.

Help that helpped,

StePhan
Jens Hollmann

Re: Using regular expressions to remove lines

Post by Jens Hollmann »

There is a search-replace-solution:

Search: ^.*\.txt\n
Replace with nothing

Regular expressions have to be turned on!.

^ Matches the beginning of a line
.* matches any character (even none) but not newline
\.txt matches the literal text ".txt". The "\" before the "." is necessary because a "." matches any single character when regular expressions are on
\n finally matches the newline

Hope that helps

Jens
Stefan

Re: Using regular expressions to remove lines

Post by Stefan »

Thanks guys, both solutions worked!

Jens' solutions was the one I was looking for.

But Stephans solution was a nice suprise to me! Thanks Stephan, as a novice user of TextPad I didn't noticed the Mark function in the Find dialog before.

TextPad keeps surprising me, and until now alway positive!
Post Reply