-1

got this get answer.

<div class="executor-item--btns">
  <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

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • I edited your question by reformatting the "get answer" but I'm not sure if it now fit's your actual question. Did I understand this correct: you were using HTTP GET to retrieve a web page and want to extract specific values from it? You want to parse the result with a regular expression to get the values `68a7c22f1d` and `1` from the above example? Did the original answer contain the escaped backslashes like `\"` does this just come from the formatting of the language? – cyberbrain Apr 03 '22 at 13:10
  • hey. thank u!! just value like - 68a7c22f1d without backslashes. – Михаил Ммк Apr 03 '22 at 15:09

2 Answers2

1

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]").

Luatic
  • 8,513
  • 2
  • 13
  • 34
0

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
Reinisdm
  • 126
  • 3