Thread: Stuf LUA help
View Single Post
11-07-17, 03:13 PM   #16
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
Ok so I took the time to understand the pattern, I might as well explain how it works.
  • ^ only matches starting from the beginning of the string.
  • -? the string will match whether it has a - character at the front or not (meaning -100000 would be broken up as -100,000 just the same as 100000 would be broken up as 100,000.)
  • %d+ matches one or more digits.
  • ^(-?%d+) matches infinitely from the beginning of the string, whether it has a leading - character or not, if there is at least one digit, until it hits a non-digit character.
  • (%d%d%d) matches three digits in a row.
  • ^(-?%d+)(%d%d%d) matches a string, whether it has a leading - character or not, with at least four leading digits (with the last three being sorted into their own separate group.)

So when you feed it a number, it'll start looking from the beginning of the string for something that may or may not begin with a - character and has at least four leading digits, stopping whenever it hits anything else (in this case, a comma character.)
After it matches, it adds a comma between the two parts.

^(-?%d+)(%d%d%d) : 10000000 --> (10000),(000) --> (10),(000),000 --> 10,000,000 (no more matches.)
  Reply With Quote