Just came across this pattern, which I really don't understand:
^[%w-.]+$
And could you give me some examples to match this expression?
Valid in Lua, where %w
is (almost) the equivalent of \w
in other languages
^[%w-.]+$
means match a string that is entirely composed of alphanumeric characters (letters and digits), dashes or dots.
Explanation
^
anchor asserts that we are at the beginning of the string[%w-.]
matches one character that is a letter or digit (the meaning of %w
), or a dash, or a period. This would be the equivalent of [\w-.]
in JavaScript +
quantifier matches such a character one or more times$
anchor asserts that we are at the end of the stringReference