Page 1 of 1

Syntax Question %d so many of these - what do they mean in this snippet?

Posted: October 21st, 2020, 10:36 am
by CodeCode
Hello, so I am going to ask for some probably obvious questions.

What do all of these %d or %a mean when used in these repeating syntax formats?:

Date.Offset:match('^([^%d]-)(%d+)[^%d]-(%d%d)')

local MatchTime = '%a%a%a (%d+) (%a%a%a) (%d+) at (%d+)%:(%d+)(%a%a)'

I know alone each one is %d Day of month as number, zero padded (01 - 31), and %a Abbreviated weekday name.

Certainly the actual meaning of the above is different? Or what do they do and mean?

Re: Syntax Question %d so many of these - what do they mean in this snippet?

Posted: October 21st, 2020, 10:40 am
by jsmorley
Those codes don't have anything to do with dates or times as such. They are codes used for "pattern matching" in Lua. Pattern matching is similar, although not identical, to regular expression.

The codes mean:

Code: Select all

.	all characters
%a	letters
%c	control characters
%d	digits
%l	lower case letters
%p	punctuation characters
%s	space characters
%u	upper case letters
%w	alphanumeric characters
%x	hexadecimal digits
%z	the character with representation 0
https://riptutorial.com/lua/example/20315/lua-pattern-matching