如何检查一个单词是否在 Lua 中的字符串中作为一个完整的单词出现 [英] how to check if a word appears as a whole word in a string in Lua
本文介绍了如何检查一个单词是否在 Lua 中的字符串中作为一个完整的单词出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不确定如何检查一个单词是否在字符串中作为整个单词出现,而不是单词的一部分,区分大小写.例如:
not sure how to check if a word appears as a whole word in a string, not part of a word, case sensitive. for example:
Play
在字符串中
Info Playlist Play pause
但不在字符串中
Info Playlist pause
Info NowPlay pause
推荐答案
由于 Lua 中没有通常的 词边界,你可以利用一个 前沿模式
%f
.%f[%a]
匹配一个字母的转换,%f[%A]
匹配相反的转换.
Since there is no usual word boundary in Lua, you can make use of a frontier pattern
%f
. %f[%a]
matches a transition to a letter and %f[%A]
matches the opposite transition.
%f[set]
,一种前沿模式;这样的项目在任何位置匹配一个空字符串,使得下一个字符属于集合而前一个字符不属于集合.集合集的解释如前所述.主题的开头和结尾被当作字符