I have a lot of badly formatted HTML which I am trying to fix using Lua for example
<p class='heading'>my useful information</p>
<p class='body'>lots more text</p>
which I want to replace with
<h2>my useful information</h2>
<p class='body'>lots more text</p>
What I am trying to use is the following Lua function which is passed the whole html page. How ever I have two problems, I want the gsub to pass the replace function the whole match including the top and tail and I will then replace the top and tails and return the string. The other problem is my inner replace function can't see the top and tail fields.
Sorry if this is an obvious one, but I am still learning Lua.
function topandtailreplace(str,top,tail,newtop,newtail)
local strsearch = top..'(.*)'..tail
function replace(str)
str = string.gsub(str,top,newtop)
str = string.gsub(str,tail,newtail)
return str
end
local newstr = str:gsub(strsearch,replace())
return newstr
end