Closed fehnomenal closed 5 years ago
According to the Lua 5.3 specification the string -
is not a pattern. Therefore the behaviour of your code is unspecified. You should escape it as %-
.
A character class is used to represent a set of characters. The following combinations are allowed in describing a character class:
- x: (where x is not one of the magic characters ^$()%.[]*+-?) represents the character x itself. ...
- %x: (where x is any non-alphanumeric character) represents the character x. This is the standard way to escape the magic characters. Any non-alphanumeric character (including all punctuation characters, even the non-magical) can be preceded by a '%' when used to represent itself in a pattern.
Alright, no worries. It just seemed strange to me that implementations allow single magic chars and do the expected thing.
Well unspecified means the implementation is free to choose a behaviour. That of course includes the behaviour you expect. You just can't be sure that your code will work across implementations/versions.
failes with a
Although the magic characters should be escaped, the demo allows them to appear in isolation.