If possible, could anyone please help me with patterns for .match .find or/and .sub as I just cannot understand patterns properly. What I basically want is a function that can rip the item name and item ID from a string regardless of what's in it. Such as:
"I wanted to go outside side today but instead I stayed in and got a new [Fancy Item of the Eagle] for my Warlock!"
"[Fancy Item of the Eagle]"
"You receive loot: [Fancy Item of the Eagle"]
"skdglksdhglkshdlgdshlgslkgsdg[Fancy Item of the Eagle]kdsflksdhg"
I just want, at the end, to have to variables (ie. iName and iID) which hold the item's name and item's ID.
I've tried lots of things, I managed to get a pattern working for "You receive loot: [Blah]" however the same pattern doesn't work for when I just link the item into the function rather than a full string with various words. I assumed it would have found it regardless of whatever was in the string I provided, since it gets parsed as Hitem:x:x:x:x and so forth, but for some reason I cannot get it to work.
What I have at the moment is:
Code:
function getItemID(item)
local iName, iID = string.find(item, "item:(%a+):(%d+):(.*)")
if ( iID == nil or iName == nil ) then
return "Couldn't get it";
else
return iName.. " + "..iID;
end
end
The return of his function is inside a DEFAULT_CHAT_FRAME:AddMessage so it'll print out.
Help very much appreciated