lua-patterns

how to check if a word appears as a whole word in a string in Lua

谁说胖子不能爱 提交于 2019-11-29 11:16:31
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. %f[set] , a frontier pattern ; such item matches an empty string at any position such that the next character belongs to set and the previous character does not belong to set. The set set is

Amount of repetitions of symbols in Lua pattern setup

◇◆丶佛笑我妖孽 提交于 2019-11-28 12:30:33
I'm looking for amount of repetitions of symbols in Lua pattern setup. I try to check amount of symbols in a string. As I read in manual , Even with character classes this is still very limiting, because we can only match strings with a fixed length. To solve this, patterns support these four repetition operators: '*' Match the previous character (or class) zero or more times, as many times as possible. '+' Match the previous character (or class) one or more times, as many times as possible. '-' Match the previous character (or class) zero or more times, as few times as possible. '?' Make the

Equivalent pattern to “[\0-\x7F\xC2-\xF4][\x80-\xBF]*” in Lua 5.1

﹥>﹥吖頭↗ 提交于 2019-11-28 08:53:20
问题 When answering this question, I wrote this code to iterate over the UTF-8 byte sequence in a string: local str = "KORYTNAČKA" for c in str:gmatch("[\0-\x7F\xC2-\xF4][\x80-\xBF]*") do print(c) end It works in Lua 5.2, but in Lua 5.1, it reports an error: malformed pattern (missing ']') I recall in Lua 5.1, the string literal \xhh is not supported, so I modified it to: local str = "KORYTNAČKA" for c in str:gmatch("[\0-\127\194-\244][\128-\191]*") do print(c) end But the error stays the same,

Lua pattern matching vs. regular expressions

不问归期 提交于 2019-11-27 17:47:48
I'm currently learning lua. regarding pattern-matching in lua I found the following sentence in the lua documentation on lua.org: Nevertheless, pattern matching in Lua is a powerful tool and includes some features that are difficult to match with standard POSIX implementations. As I'm familiar with posix regular expressions I would like to know if there are any common samples where lua pattern matching is "better" compared to regular expression -- or did I misinterpret the sentence? and if there are any common examples: why is any of pattern-matching vs. regular expressions better suited? Are

Amount of repetitions of symbols in Lua pattern setup

纵饮孤独 提交于 2019-11-27 07:04:24
问题 I'm looking for amount of repetitions of symbols in Lua pattern setup. I try to check amount of symbols in a string. As I read in manual, Even with character classes this is still very limiting, because we can only match strings with a fixed length. To solve this, patterns support these four repetition operators: '*' Match the previous character (or class) zero or more times, as many times as possible. '+' Match the previous character (or class) one or more times, as many times as possible. '