I am trying to do a pattern search, but it doesn't work. I have this code:
vars = "CmdTurn.on=off/GetPar.pwd=true"
_GET = {}
for k, v in string.gmatch(vars, "(%w+)(%p+)(%w+)=(%w+)&*") do
_GET[k] = v
print(k..":"..v)
end
After run this code I hope see this result:
CmdTurn.on:off
GetPar.pwd:true
But it doesn't work. The wrong result that appears is this one:
CmdTurn:.
GetPar:.
Any one could help me?
There are multiple capture groups in the pattern (%w+)(%p+)(%w+)=(%w+)&*, so k and v gets the result of the first two captures, which is not what you want.
Try this:
for k, v in string.gmatch(vars, "(%w+%p+%w+)=(%w+&*)") do
print(k..":"..v)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With