views:

68

answers:

2

How to add title of link as a alt of img. using regex and in dreamweaver. I have to do in a large document. and in multiple files

Before

<a title="Whatever is written here" href="#" target="_blank">
<img width="14" height="14" src="#" /></a>

after

<a title="Whatever is written here" href="#" target="_blank">
<img width="14" height="14" src="#" alt="Whatever is written here" /></a>
A: 

The best way to do this is to write a script in some scriptiong language (ruby, python etc.) that:

  1. Goes through all the files
  2. Finds in file <img> tag.
  3. Checks whether there is an <a> around it (as parent)
  4. Puts value of the img.alt to a.title.

There are already some libraties to parse html/xml (ruby.hpricot for example)

Draco Ater
but i don't know ruby python etc.
metal-gear-solid
+1  A: 

Try searching for

(<a[^>]+?title=")([^"]*)("[^<]+<img)

and replacing with

$1$2$3 alt="$2"

This assumes that there is no other tag between the <a> tag and the <img> tag, and that there are no (escaped) quotes inside the title attribute.

EDIT: Changed \1 backreference syntax to $1.

Tim Pietzcker
not working i tried - http://shup.com/Shup/303637/110227231011-My-Desktop.png
metal-gear-solid
Please try an alternate syntax: Use `$1$2$3 alt="$2"` as replace string.
Tim Pietzcker
cool it's working. thanks very much.
metal-gear-solid