Thread Tools Display Modes
11-12-11, 09:28 AM   #1
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Lua pattern matching

Hi,

I've been trying to remove the server name from players in chat, or even replace it, for example, from PlayerX - ServerY to playerX (*)

Actually, i need to do this is the chat but also in another addon (bars that display the player's name)

Example (wrong of course): local test3 = string.gsub(unit, "%-.+", " (*)")


Thing is, i su** at this. Could anyone tell me how to do both situation (remove or replace with (*) please ?tell me how to do both situation (remove or replace with (*) please ?
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }

Last edited by Caellian : 11-12-11 at 09:45 AM.
  Reply With Quote
11-12-11, 01:37 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Actually, that should work. Sometimes they add spaces around the hyphen, which can be removed too.

Code:
name:gsub("%s*%-.*"," (*)");
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
11-12-11, 02:01 PM   #3
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
I'm not really helping, but maybe an useful resource --in this link they discussed on just removing the server name from Combat Log names, instead of replacing it with an *

http://forums.wowace.com/showthread.php?t=19477#9

Last edited by Ketho : 11-12-11 at 05:08 PM.
  Reply With Quote
11-13-11, 02:57 PM   #4
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Originally Posted by SDPhantom View Post
Actually, that should work. Sometimes they add spaces around the hyphen, which can be removed too.

Code:
name:gsub("%s*%-.*"," (*)");

The space, yep, good catch, thanks, and yeah btw, my example worked... lol
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
11-21-11, 02:13 AM   #5
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
I'm pretty noob at the whole pattern matching thing as well. Is there a way to remove duplicate letters in a string using pattern matching?

start: Neaaakkoooooooooo
finish: Neako

Code:
msg:gsub(msg, "[^a-zA-Z]+", "")
I have this so far to basically remove anything that's not a standard letter.
  Reply With Quote
11-21-11, 03:43 AM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Lua doesn't have a strong pattern matching system like Perl, PHP, etc. You'll have to do a separate check like "[Aa][Aa]+" would match 2 or more A's.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Lua pattern matching


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