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
is in strings
Info Playlist Play pause
but not in the strings
Info Playlist pause
Info NowPlay pause
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
is in strings
Info Playlist Play pause
but not in the strings
Info Playlist pause
Info NowPlay pause
Since there is no usual
\b
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.You can use the following
ContainsWholeWord
function:See IDEONE demo
To fully emulate
\b
behavior, you may usepattern, as
\b
matches the positions between:[a-zA-Z0-9_]
) character.[a-zA-Z0-9_]
) character.[a-zA-Z0-9_]
) and the other is not a word character ([^a-zA-Z0-9_]
).Note that
%w
Lua pattern is not the same as\w
since it only matches letters and digits, but not an underscore.