I am writing an external AddOn that converts invalid itemID lists into valid ones for TradeSkillMaster. However, for all that I have been reading on wowpedia.org and the official Lua documentation, I am stuck on matching exactly what I want in strings.
These are valid for TSM:
- "i:82977"
- "i:82977,i:10368"
While these are not valid:
TSM requires itemIDs in the format "i:12345" and comma seperated if there are more than one. Okay, great. I can use string.gmatch (I don't care about what position the numbers are, so I'm not using string.match) like so:
Code:
local maybe_valid = string.gmatch(myString, "%d+$"
But that will match both examples above, valid and not valid. That won't work. How do I force the match to start at the first character of the string?
Checking if it is valid is easy, I think.
Code:
local valid = string.gmatch(myString, "i:%d+$"
The reason for knowing the difference is that after finding invalid strings, I will use string.gsub(myString, ",", ",i:") to fix them. Clearly I don't want to fix a string that is already valid.