gpt4 book ai didi

string - Lua string.match() (Corona SDK)

转载 作者:行者123 更新时间:2023-12-02 00:08:15 24 4
gpt4 key购买 nike

我正在尝试从服务器响应中提取授权代码,例如:

GET/?state=authenticated&code=U946s9lHouBGWy8o45bXSRSXGzTqd0Ys HTTP/1.1

我正在使用 lua/Corona;

string.match(request, "GET /?state=authenticated&code=([%w--_/.=?]+)")

我没有收到任何回复,也不知道我做错了什么……有人知道或有更好的主意吗?

wkr,

-肖恩

最佳答案

字符 ? 本身充当模式修饰符。这就是您得到 nil 结果的原因。使用 % 进行转义。

str = "GET /?state=authenticated&code=U946s9lHouBGWy8o45bXSRSXGzTqd0Ys HTTP/1.1"

print( str:match("GET /%?state=(%w+)&code=(%w+)") )

这是工作输出:https://eval.in/33065


编辑

这里是 another example同样,不转义 ? 字符。这只是为了阐述我的观点。 :)

关于string - Lua string.match() (Corona SDK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17004994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com