Using lua script I want to find sting inside string. This is how I am trying but not working.
local mystring="<span class="my-author"><a href="http://aaaa/author/abb-abbb/" title="Posts by abb" class="author" rel="author">abc xyz</a></span>"
local x, y= string.find(mystring,'<span class=\"my-author"\>')
local w, z = string.find(mystring,'</a></span>)
local author
if y==nil or w==nil then
print(author)
else
author = string.sub(mystring, y+1, w-1)
print(author)
end
How do I find string inside <span class>
.
Thanks,
答案 0 :(得分:0)
You need to make sure your pater
in find
will not get
local mystring='<span class="my-author"><a href="http://aaaa/author/abb-abbb/" title="Posts by abb" class="author" rel="author">abc xyz</a></span>'
local x, y = string.find(mystring,'<span class="my-author">', 0, true)
local w, z = string.find(mystring,'</a></span>', x, true)
local author
print(x,y,w,z)
if y==nil or w==nil then
print(author)
else
author = string.sub(mystring, y+1, w-1)
print(author)
end