regexmacrabbit-espresso

Extracting the title attribute with Regex


Search

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

replace with

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

or just (my second choice, good enough)

<figcaption>caption here</figcaption>

How do I search and replace with regex? I am using TextMate and Espresso. I am not searching in a HTML file, this HTML is small part of my Drupal post. I learnt I should be using a HTML parser. I believe this case is simpler.


Solution

  • Try searching with:

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

    and replace with:

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