Thread Tools Display Modes
12-08-05, 04:43 AM   #1
Szandos
A Defias Bandit
Join Date: Aug 2005
Posts: 3
Question 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
  Reply With Quote
12-08-05, 07:38 AM   #2
Elkano
A Flamescale Wyrmkin
 
Elkano's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 131
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
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Paring parameters with regexp


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off