Answer the question
In order to leave comments, you need to log in
How to get content between tags in a string using string.find?
--получаем позиции содержимого в строке вместе с тегами
i, j = string.find (data, "<body>(.-)</body>")
--отнимает количество символов эквивалентных размерам тегов
msg = string.sub (data, i + 6, j - 7)
Answer the question
In order to leave comments, you need to log in
Like this?
repl.it/408/2
local data = 'asdds d sf fsadsadsad<body onload="javascrip:()">the text inside the tag</body>asdsadas ds fsd sdf dsadsad'
local tag = 'body'
local tagStart, tagEnd = data:find('<' .. tag .. '.->')
local closeTagStart, closeTagEnd = data:find('</' .. tag .. '.->', tagEnd + 1)
local textStart, textEnd = tagEnd + 1, closeTagStart - 1
local msg = data:sub(textStart, textEnd)
print(msg)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question