簡體   English   中英

使用Regex提取title屬性

[英]Extracting the title attribute with Regex

搜索

<img src="images/foo.jpg" alt="" title="caption here" class="figure" />

用。。。來代替

<img src="images/foo.jpg" alt="" title="caption here" class="figure" /><figcaption>caption here</figcaption>

或者只是(我的第二選擇,足夠好)

<figcaption>caption here</figcaption>

如何搜索並用正則表達式替換? 我正在使用TextMate和Espresso。 我不是在HTML文件中搜索,該HTML僅是我的Drupal帖子的一小部分。 我了解到我應該使用HTML解析器。 我相信這種情況比較簡單。

嘗試搜索:

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

並替換為:

$1$2$3<figcaption>$2</figcaption>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM