I'm trying to replace within a tag? EX:
mystr = '<html><head></head><body><p>Aqui meu texto</p></body></html>'
mystr = mystr:gsub('<.+>', '')
print(mystr)
I would like it to return:
Aqui meu texto
But it does not return anything.
I'm trying to replace within a tag? EX:
mystr = '<html><head></head><body><p>Aqui meu texto</p></body></html>'
mystr = mystr:gsub('<.+>', '')
print(mystr)
I would like it to return:
Aqui meu texto
But it does not return anything.
The problem is that '<.+>'
houses all the string and gsub
then removes all content.
If you want to extract text, use string.match
and captures:
print(mystr:match('<p>(.-)</p>'))
If you want to replace the text, use
mystr = mystr:gsub('<p>.-</p>','<p>Eis o novo texto</p>',1)