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
Lua Patterns
Actually it will match nothing. Because there is an error: w-
this is a start of a text range and it is out of order. So it should be %w\-
instead.
^[%w\-.]+$
Means:
^
assert position at start of the string[%w\-.]+
match a single character present in the list below
+
Quantifier: Between one and unlimited times, as many times as possible, giving back as needed [greedy]%w
a single character in the list %w literally (case sensitive)\-
matches the character - literally.
the literal character .$
assert position at end of the stringEdit
As the OP changed the question and the tags this answer no longer fits as a proper answer. It is POSIX based answer.
As @zx81 comment:
%w
is \w
in Lua which means any alphanumeric characters plus "_"If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With