How to duplicate "title" <a> as a "alt" of "img". using regex, manually?
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" hei开发者_StackOverflow社区ght="14" src="#" alt="Whatever is written here" /></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
.
The best way to do this is to write a script in some scriptiong language (ruby, python etc.) that:
- Goes through all the files
- Finds in file <img> tag.
- Checks whether there is an <a> around it (as parent)
- Puts value of the img.alt to a.title.
There are already some libraties to parse html/xml (ruby.hpricot for example)
精彩评论