It is currently December 3rd, 2020, 10:01 am

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

Discuss the use of Lua in Script measures.
User avatar
CodeCode
Posts: 178
Joined: September 7th, 2020, 2:24 pm

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

Post 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?
Can't fix it if it ain't broke - unless it is in code.
User avatar
jsmorley
Developer
Posts: 21520
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post 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