Answer the question
In order to leave comments, you need to log in
How to specify the number of characters in a regular expression in lua?
local string = "qw.erty"
return string:match("([a-z]{2})%.")
Answer the question
In order to leave comments, you need to log in
For starters, it's best not to use a word string
for the variable name, as it's a whole library for working with strings. You block access to it.
Lua does not have full-fledged regular expressions, because Lua was conceived as the lightest possible language. Instead, the so-called. "pattern match". So that {2}
doesn't work. It's just that in most cases modifiers are enough. + - * ?
In your case, it will do:
local str = "qw.erty"
return str:match("([a-z][a-z])%.")
local str = "qw.erty"
return str:match("(%l%l)%.")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question