string.gsub() and regular expression
I need to get text without a comma in numbers using string.gsub() function:
Code:
local text = "The number 45,678 is big, but 1,234 is small." |
back in legion, this is how I got the numbers, and only the numbers, out of the artifact power item tooltips without seperators. You can modify this to do what you want (I would guess).
Code:
appower = string.match(_G[self:GetName().."TextLeft"..i]:GetText(), "%d+%,?%.?%s?%d*"); |
Lua Code:
|
Lua does not use regex. It has a similar but limited engine:
https://wow.gamepedia.com/Pattern_matching In this case, since I assume you want to keep the comma in the center, you need %d with parenthesis and then %# in the replacement argument Lua Code:
The %d,%d captures any comma surrounded by numbers, the parenthesis "saves" the two numbers, and %1%2 outputs those two numbers in place without the comma. |
Yes, this is the solution.
text = string.gsub(text, "(%d),(%d)", "%1%2") Thanks, Kanegasi. |
Is there any benefit to doing it that way? The method briskman3000 and I posted seems about twice as fast when benchmarking. (Though the processing time probably doesn't matter much for the OP's needs.)
|
Quote:
Using the OP's sample text: Code:
"The number 45,678 is big, but 1,234 is small." Code:
"The number 45678 is big, but 1234 is small." Code:
"The number 45678 is big but 1234 is small." |
Of course. I wasn't thinking that he wanted to pass that entire string through it.
|
All times are GMT -6. The time now is 08:09 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI