Quantcast
WoWInterface - View Single Post - Pattern matching
View Single Post
10-22-19, 11:50 AM   #1
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 176
Pattern matching

I try to extract the itemId from a loot message but am not sure how to do this.

For example I have the following loot message.
"You receive loot: |cffffffff|Hitem:2589::::::::13:::::::|h[Linen Cloth]|h|r."

I use the this funtion to extract the number:
Lua Code:
  1. -------------------------------------------------------------------------------
  2. --  Extract the number from a message
  3. -------------------------------------------------------------------------------
  4. local CA_match_number
  5. local function ClassicAchievements_Match_number(line)
  6.     CA_match_number, = string.match(line,"%d+")
  7.     if CA_match_number ~= nil then
  8.         print(CA_match_number)
  9.         return(CA_match_number)
  10.     end
  11.     return(0)
  12. end

This will work just fine is the itemId is the biggest number in the message.
But it will fail if there is a bigger number in the message.

It there a way to extract the first number from a text string?
__________________
Better to fail then never have tried at all.
  Reply With Quote