[Webchange-list] Search and Replace

Vince M Hudd vince at softrock.co.uk
Mon Jan 10 11:52:24 GMT 2011

Tim Hill <tim at timil.com> wrote:


> For years I have religiously been ensuring (most of) my Imgs have Alt tags
> but none of the tools I use automatically inserts a Title.

That's a good point - I should really expand the alt text inserter to also
insert titles. The same limitations would apply, though, in that it would
only be able to sensibly include a set piece of text or the image leafname.

> Naturally I turned to WebChangePro to add titles, and want to copy the alt
> tag text in the process or the leafname if there is none.
> I have hit a brick wall in trying to do this as I can't see how to include
> part of a found string in the replace string.
> I am sure I must be being thick: any pointers will be welcome. Please.

It can indeed be done, but I'm sat at the wrong computer, on the wrong desk,
in the wrong office. So, from memory, the way to insert a matched wildcard
is to use an asterisk (for a multi-character wildcard) followed by its index
number and a semi-colon to terminate that number. I *think* the index
numbers start from 1, and there are a maximum of 99. Therefore, one of these
should, I hope, do it:

The simplest would be:

 Replace: alt="*"
    With: alt="*1;" title="*1;"

If you want to ensure you're in the context of an image tag, then:

 Replace: <img *alt="*"*>
 With:    <img *1;alt="*2;" title="*2;"*3;>

The extra wildcards in that are to ensure anything else that may be between
the img and alt or alt and > is maintained.

The flaw in either of these, though, is that if you have any img tags that
already have titles, they'll now have two.

Another, slightly more crafty approach:

  Replace: <img*alt*>
     With: <img*1;title*2;>

Followed by running the alt text inserter. :)

Or even avoiding wildcards altogether:

  Replace: alt=
     With: title=

Again, followed by the alt text inserter. Obviously, this last case assumes
alt= doesn't appear anywhere else in your html.

Vince M Hudd: http://misc.vinceh.com Soft Rock: http://www.softrock.co.uk

More information about the Webchange-list mailing list