Replacing HTML tags around pieces of text

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
seanap
Posts: 2
Joined: Tue Jun 03, 2008 8:02 pm

Replacing HTML tags around pieces of text

Post by seanap »

First off I've got to say I LOVE TextPad! But anyways, I'm trying to replace the HTML tags around certain portions of text as to quickly assist in moving a file over to a CSS style sheet.

What I'm trying to replace looks like this:

Code: Select all

<TD WIDTH="50" ALIGN="RIGHT" ><FONT SIZE="3"><STRONG><FONT COLOR="BLACK">88</STRONG></FONT></TD>
and I would want to replace it with something like this:

Code: Select all

 <td class="blue">88</td>
I'm sort of new to Regular Expressions, so any help and guidance would be greatly appreciated!
gan

Post by gan »

It'a always a bit hard to give a working example with only one line of example since the other lines might be different and the example might not work for those lines. Anyway for your current example this one should work:

Search for:

Code: Select all

<TD.*(>[^<>]+<).*/TD>
And replace with:

Code: Select all

<td class="blue"\1/td>
I don't know what the rest of the lines look like so might be some lines where it doesn't match correctly. In that case you need to provide some more lines in your example and include the lines where this doesn't work. Maybe some small adjustments is required to make it work or maybe it's a bit harder then it seems.
seanap
Posts: 2
Joined: Tue Jun 03, 2008 8:02 pm

Post by seanap »

I'm not at work right now (won't be until Monday) so I can't provide any more examples, however the majority of the lines that need to be replaced are very similar to that, i.e. just different widths or attributes, etc.

I'll give what you posted a try as soon as I can.

Thanks for the reply, I do greatly appreciate it!
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

The real complication in this example will be if the closing tag is not always on the same line.

If the information inside the tags goes across more than one line, then you may have to do multiple passes, each one designed to handle a different number of enclosed lines.

So a good sample of lines should be included showing all combinations to be searched.....
Hope this was helpful.............good luck,
Bob
Post Reply