got this get answer.
<div >
<form name="UserResetAccount" onsubmit="event.preventDefault(); return false;">
<input type="hidden" name="UserResetAccount[nonce]" value="68a7c22f1d">
<input type="hidden" name="UserResetAccount[network]" value="1">
how to get value from "UserResetAccount[nonce]" value="THIS VALUE"
and from "UserResetAccount[network]" value="THIS VALUE"
using string.match
?
thank u
CodePudding user response:
with string.gmatch
this way:
for fieldname, value in str:gmatch("UserResetAccount%[(.-)%].-value=\"(.-)\"")do
print(fieldname .. "=>" .. value)
end
with your example output:
nonce => 68a7c22f1d
network => 1
CodePudding user response:
You can't adequately parse HTML with regular expressions. Lua patterns are slightly more powerful in some aspects (but also slightly weaker in other, more basic ones) than regular expressions yet still not powerful enough to fully parse HTML. Everything using patterns or regular expressions is bound to fail for more complex or specially crafted documents.
You should use a proper HTML parser such as Gumbo. Depending on the parser you use, you might use XPath or CSS selectors (input[name="UserResetAccount[nonce]"]
) to obtain the value of that input
element (if you use Gumbo, you can use getElementsByTagName("input")
and then loop over the element list to search for the element with name == "UserResetAccount[nonce]"
).