I have a string
text 6ffdfd <a href="http://worldnews.com" target="_blank">toto</a> sdsdsd
I would like to find a regex that would
- add a opening span tag just after the end of the a tag html link (that is to say to be precise after the string "target="_blank">"
- add a closing span tag just before the a tag closing
The desired end result would be:
<a href="http://worldnews.com" target="_blank"><span>toto</span></a> sdsdsd
For the moment , I don't find how to achieve 1, and I only partially managed 2. because my current code is wrongly adding white space that I don't want between /span and the closing a tag
Current code
orig_string = 'text 6ffdfd <a href="http://example.com" target="_blank">toto</a> sdsdsd'
end_result = orig_string.gsub(/<\/a>/, '</span> \\0')
print end_result
I have a set up a online editable DEMO here: https://repl.it/repls/SecondCapitalPika