wpr*_*ins 1 string lua match
我试图在 Lua 中找到字符串的精确匹配,包括特殊字符。我希望下面的示例返回它是完全匹配的,但是由于-它返回的字符nil
-
nil
index = string.find("test-string", "test-string") 返回零
index = string.find("test-string", "test-string")
index = string.find("test-string", "test-") 返回 1
index = string.find("test-string", "test-")
index = string.find("test-string", "test") 也返回 1
index = string.find("test-string", "test")
我怎样才能让它做完全匹配?
Lia*_*ler 5
-是 Lua 字符串模式中的模式运算符,所以当你说 时test-string,你是在告诉尽可能少find()地匹配字符串test。所以发生的事情是它在那里test-string查看,test在那里看到,并且由于-在这种情况下不是实际的减号,它实际上是在寻找teststring.
test-string
find()
test
teststring
按照迈克所说的去做,然后用%角色逃避它。
%
我发现这有助于更好地理解模式。
归档时间:
9 年,10 月 前
查看次数:
370 次
最近记录: