如何复制“标题”<a> as a &#34;alt&#34; of &#34;img&#34;. using regex, manually?</a>

时间:2010-03-27 11:09:48

标签: regex xhtml dreamweaver

如何添加链接标题作为img的alt。使用正则表达式并在Dreamweaver中。我必须在一份大文件中做。并在多个文件中

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

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

2 个答案:

答案 0 :(得分:1)

尝试搜索

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

并替换为

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

这假设<a>标记和<img>标记之间没有其他标记,并且title属性中没有(转义)引号。

编辑:将\1反向引用语法更改为$1

答案 1 :(得分:0)

执行此操作的最佳方法是使用以下编写语言(ruby,python等)编写脚本:

  1. 浏览所有文件
  2. 在文件中查找&lt; img&gt;标签
  3. 检查是否有&lt; a&gt;在它周围(作为父母)
  4. 将img.alt的值设为a.title。
  5. 已经有一些libraties来解析html / xml(例如ruby.hpricot