WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Paring parameters with regexp (https://www.wowinterface.com/forums/showthread.php?t=2587)

Szandos 12-08-05 04:43 AM

Paring parameters with regexp
 
Need help in parsing the parameters to my slash command. I am doing a slash command that takes two parameters in the form "myCmd param1 param2". However, the params can contain spaces and thus should be in "", but I still would like to not have that when they don't contain spaces. Example:

myCmd mace sword
myCmd "mace of destruction" "sword of power"

I guess I have to use string.find to get the parameters out, but how would I do???

Thanks
Roberto

Elkano 12-08-05 07:38 AM

You could try the following (I'm not sure it will work 'cause I haven't tested it, but I think it will):
Code:

function getparams(text) {
  _, _, match, match2 = string.find(text, "\"([^\"]+)\" \"([^\"]+)\"");
  if match ~= nil then return match;
  _, _, match, match2 = string.find(text, "\"([^\"]+)\" ([^\"]+)");
  if match ~= nil then return match;
  _, _, match, match2 = string.find(text, "([^\"]+) \"([^\"]+)\"");
  if match ~= nil then return match;
  _, _, match, match2 = string.find(text, "([^\"]+) ([^\"]+)");
  if match ~= nil then return match;
  retun nil;
}

Here is a link to the lua manual, where you may find other usefull information regarding pattern matching in lua (linked page and followups): http://www.lua.org/pil/20.html


All times are GMT -6. The time now is 05:55 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI