finding the last instance of a string

General questions about using TextPad

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

Post Reply
kdelacruz
Posts: 4
Joined: Fri Dec 12, 2008 11:12 pm

finding the last instance of a string

Post by kdelacruz »

Hello,

I have many files containing text like:

%ENDSECTION{name="operatoraddrsection1"}%

%ENDSECTION{name="operatoraddrsection2"}%

%ENDSECTION{name="operatoraddrsection3"}%

There might be any number of these lines (each with a different number at the end, depending on how many are in that particular file) .

I want to add a line of text just after the LAST one of these in each file by using search and replace -- but ... how can Textpad find which is the last one?

Thanks!
User avatar
helios
Posts: 710
Joined: Sun Mar 02, 2003 5:52 pm
Location: Helios Software Solutions
Contact:

Post by helios »

Try this:

Ctrl+End to take the cursor to the end of the file.
Open the Find dialog box and enter the following in the Find what section:

(%ENDSECTION{name="operatoraddrsection[0-9]+"}%)

Check the Conditions for Text and Regular expression and the Direction as Up
Press Find next. This should find the last instance in the file.
Open the Replace dialog box. Type in the Replace with section:

\1\nthe text I want to insert

Press Replace

I have used POSIX regular expression syntax, which can be selected from the Editor page of the Preferences dialog box.

If the text you want to insert is the same for every file, you could record a macro using the same steps described above, and then run this on each file.

I hope this helps.
Helios Software Solutions
Post Reply