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
We can't but admit that Lua regex quantifiers are very limited in functionality.
+
, -
, *
and ?
)As a "work-around", in order to use limiting quantifiers and all other PCRE regex perks, you can use rex_pcre library.
Or, as @moteus suggests, a partial workaround to "emulate" limiting quantifiers having just the lower bound, just repeat the pattern to match it several times and apply the available Lua quantifier to the last one. E.g. to match 3 or more occurrences of a pattern:
local np = 'abc_123'
local a = np:match('^[a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_]+$' )
See IDEONE demo
Another library to consider instead of PCRE is Lpeg.