Help with Search/Replace

General questions about using TextPad

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

Post Reply
Karen0302
Posts: 1
Joined: Tue Sep 06, 2005 12:46 am

Help with Search/Replace

Post by Karen0302 »

Hi,

I have a large file that has imbedded control codes in it that I need to change to HTML tags. The code I am interested in changing is for italics. The file uses a \i to begin italics and another \i to end them.

Any help on how I can change these to HTML tags would be much appreciated!

Karen
User avatar
webber123456
Posts: 50
Joined: Wed Jul 30, 2003 2:55 am

Post by webber123456 »

Try a simple test:

Convert all to <i> then run through tidy and it should correct for closing tag

I tried this on a small file and it seemed to work.

Otherwise, you may need to write a script or just step through the file manually with the replacements needed
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Because the same symbol is used to start and end the italicised text, this is quite hard.

If each section of italicised text begins and ends on the same line, and if there is at most one such section on any one line, then you can use the following:
Find what: \\i(.*)\\i
Replace with: <i>\1</i>

[X] Regular expression
This assumes you are using POSIX regular expression syntax:
Configuration | Preferences | Editor

[X] Use POSIX regular expression syntax
This doesn't work in TextPad if the italicised sections span newlines, as TextPad's regular expression recogniser doesn't support regular expressions containing variable numbers of newlines.

It also doesn't work in TextPad if there is more than one italicised section on one line, as the above regular expression will match everything from the first \i on the line to the last \i on the line. If there are no backslahes (\) within the italicised sections, you can avoid this problem with
Find what: \\i([^\]*)\\i
Replace with: <i>\1</i>

[X] Regular expression
Better solutions are available with WildEdit (http://www.textpad.com/products/wildedit/), which uses the far more powerful Boost regular expression recogniser. In WildEdit
Find what: \\i(.*?)\\i
matches lazily (matching the shortest subexpression instead of the longest), solving the second problem above. And you can choose to have a dot (.) match newlines, solving the first problem.
User avatar
BriAnn
Posts: 13
Joined: Thu Sep 18, 2003 1:58 am

Post by BriAnn »

It's probably too late to be of use by now, but FWIW, I'd change all of the /i to <i>. Then, I'd create a short macro that
searched for <i>
searched for <i>
moved one character to the right
inserted /
That is, it would insert a / in every other <i>
Post Reply