是否有匹配不以 a 开头的字符串的模式!,我在 Google 和 SO 中搜索,似乎 Lua 没有“非模式”。
!xxxx yyyy--match
!?????? --match
?? --not match
test string --not match
Run Code Online (Sandbox Code Playgroud)
锚点^匹配字符串的开头。
要匹配以 开头的字符串!,请使用以下模式:
"^!"
Run Code Online (Sandbox Code Playgroud)
要匹配不以 开头的字符串!,请使用以下模式:
"^[^!]"
Run Code Online (Sandbox Code Playgroud)
其中[^!]匹配任何不是 的字符!。
您可以not按如下方式使用运算符:
if not str:match "^!" then
-- what you wanted to do
end
Run Code Online (Sandbox Code Playgroud)