local querycreate = "create user 'dddqwd123_dwqd'@'localhost'"
local create, usercreate, username, userhost = querycreate:match("^(%w+)%s+(%w+)%s+\'(%w)\'@\'(%w)\'$")
print(string.format("query: %s", querycreate))
print(string.format(" var create = %s \n var usercreate = %s \n var username = %s \n var userhost = %s", create, usercreate, username, userhost))
query: create user 'dddqwd123_dwqd'@'localhost'
var create = nil
var usercreate = nil
var username = nil
var userhost = nil
我的正则表达式在http://regexr.com?37voi上运行良好。
如果我将其更改为("^(%w+)%s+(%w+)%s+")
,它将输出:
var create = create
var usercreate = user
var username = nil
var userhost = nil
如果我querycreate
通过将引号设置为"create user dddqwd123_dwqd @ localhost"
并使用来删除引号^(%w+)%s+(%w+)%s+(%w+) @ (%w+)$
,那么输出是正常的。