문제

Im trying to pull the auth code out of a server response like:

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

I am using the lua/Corona;

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

I am getting a nil response and have no idea what Ive got wrong...anyone know or have a better idea?

wkr,

-sean

도움이 되었습니까?

해결책

The character ? on its own, acts as a pattern modifier. This is why you get nil result. Use a % to escape this.

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

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

Here is working output: https://eval.in/33065


EDIT

Here is another example for the same, without escaping the ? character. This is just to elaborate my point. :)

다른 팁

Try to use this:

string.match(request, "GET /%?state=authenticated&code=([^ ]+)")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top