I have an HTML string containing multiple <image> tags. I’d like to search for each tag and wrap them with a div tag.
For example:
mplampla<img src="somethin.jpg" />mplampal
Should be:
mplampla<div class=""><img src="something" /></div>mplamla
How can I do this using Regex within Ruby on Rails?
If I properly understand what you need:
Here we’re using named capturing groups using the \k named backreference syntax:
(?<img>...)creates named group and\k<img>uses backreference.UPDATED
We also have to use non-greedy quantificator – thanks @mu! – for working with nested tags