Regular Expression Find and Replace on HTML tags

General questions about using TextPad

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

Post Reply
burtonfigg
Posts: 11
Joined: Wed Jun 01, 2005 6:37 pm

Regular Expression Find and Replace on HTML tags

Post by burtonfigg »

I have a table with "news" in it. Some of the content contains links to other sites in the form of html markup. I have extracted the data into a text file, and I want to tidy it up so that it validates as xhtml strict.

So, if I had this for example:

Here is some news about <a href=http://www.google.com>google</a> which I read today

I would want to do a Find and Replace in TextPad to convert it to:

Here is some news about <a href="http://www.google.com">google</a> which I read today

That's all it is - to put the URL in speech marks. I could do half of it with a simple find and replace:

find: <a href=http and replace with: <a href="http

But then the complicated bit is to close the speech marks.

I was hoping that this is something that could be done using a regular expression in the Find and Replace section, but I can't work out how to do it.

I tried something like

find: <a href=[*]> and replace with <a href="[*]">

But obviously this is way too simplistic, and wrong.

If anyone can advise about how I can do this it would be much appreciated. I have read guides and tutorials on RegExpressions but find them totally incomprehensible!

Thanks

Jim
User avatar
s_reynisson
Posts: 939
Joined: Tue May 06, 2003 1:59 pm

Post by s_reynisson »

Find (<a href=)([^>]+)(>[^>]+>)
Replace \1"\2"\3
Should get you started and pls note that I have used POSIX regular expression syntax, which can be selected from the Editor page of the Preferences dialog box. HTH
Then I open up and see
the person fumbling here is me
a different way to be
burtonfigg
Posts: 11
Joined: Wed Jun 01, 2005 6:37 pm

Thanks!

Post by burtonfigg »

Thanks very much - that worked without a problem! Excellent...

Jim
Post Reply