I have a chunk of HTML that contains multiple <img> tags. The current format of the tag is:
<img width="580" height="183" src="/images/stories/acidalkalinetable.jpg" alt="acid alkaline table" title="Body pH Balance">
I want to go through the html and for each <img> tag change the format to:
<img width="580" height="183" src="{{media url="wysiwyg/acidalkalinetable.jpg"}}" alt="acid alkaline table" title="Body pH Balance">
You can see it's the src that's changing. I've kept the filename but changed other parts of the src
If the img was a single string I could do something like:
content = '<img width="580" height="183" src="/images/stories/acidalkalinetable.jpg" alt="acid alkaline table" title="Body pH Balance">'
filename = re.search(r'/images/stories/\w+\.(jpg|png|gif)', content)
new_content = re.sub(r'/images/stories/\w+\.(jpg|png|gif)', '{{media url="wysiwyg/' + filename + '"}}', content)
(I haven't tested that)
But I'm not sure how I can do that for each occurrence of the <img> tag in HTML
"{{media url="wysiwyg/acidalkalinetable.jpg"}}", the wsiwyg part is outside the quote.