开发者

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:

  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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜