如何在lua中检查url是否有效? [英] How to check url whether url is valid in lua?
本文介绍了如何在lua中检查url是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查 url 是否有效,在 lua 中正确的正则表达式是什么?我试过这样的正则表达式
I want to check if url is valid, what is the correct regexp to do that in lua? I tried regexp like this
string.match('https://stackoverflow.com/', '[a-z]*:\/\/[^ >,;]*')
但出现错误
invalid escape sequence near ''[a-z]*:\/'
更新:
string.match('https://stackoverflow.com/', '[a-z]*://[^ >,;]*')
正确答案
推荐答案
错误很明显:\/
是无效的转义.您不需要转义 /
,因为它不是 Lua 模式中的特殊字符 (检查魔法"字符列表)并删除转义符应该可以工作:string.match('https://stackoverflow.com/', '[az]*://[^ >,;]*')
.
The error is fairly clear: \/
is an invalid escape. You don't need to escape /
, as it's not a special character in Lua patterns (check the list of "magic" characters) and removing the escape should work: string.match('https://stackoverflow.com/', '[a-z]*://[^ >,;]*')
.
这篇关于如何在lua中检查url是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文