3

i am working on generating License keys in LUA. I want to separate the characters with the "-" of every 5 set of character. the number of character will remain 40 Always. so far i have found one code that worked for string that includes only numbers but mine has both numbers and alphabets. so i am looking for the pattern that works. Thanks in advance.

a=("060c9da4df0ee2e06ea99abde72545fe2a1b8d52"):gsub(("(pattern)"):rep(8), "%1-%2-%3-%4-%5-%6-%7-%8")

print(a)

output like: 060c9-da4df-0ee2e-06ea9-9abde-72545-fe2a1-b8d52

1 Answer 1

5

Try this:

a=("060c9da4df0ee2e06ea99abde72545fe2a1b8d52"):gsub(("."):rep(5),"%1-"):sub(1,-2)

1
  • 1
    This'll produce sets of 8 characters. rep(8) should be rep(5) :)
    – Advert
    Jul 31, 2014 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.