Thread Tools Display Modes
05-24-13, 12:58 PM   #1
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Pattern matching

I want to shorten mob names from say "Sun Weaver Archer" to "S. W. Archer". I use
Code:
string.gsub(name, "%s?(.[\128-\191]*)%S+%s", "%1. ")
which I found in an addon I use, but must admit I don't understand how it works. What is the .[\128-\191] part supposed to mean? '.' stands for a single character and the next part is a range of ascii codes from 128 to 191. I found out this is to make it work for non-English languages, as it doesn't work if I use
Code:
string.gsub(name, "%s?(%S)%S+%s", "%1. ")
.

The other problem I have is when I run this for name = "Echo of a Pandaren Monk", it would return "E. o. aP. Monk" (no space between a and P.). How would I fix this.

Would appreciate some explanations about this.
  Reply With Quote
05-24-13, 08:23 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
See here:
http://www.wowinterface.com/forums/s...ad.php?t=46497

Since that thread is about the same thing, any replies should be posted there, so the discussion stays in one place.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-24-13, 09:36 PM   #3
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Thanks for the pointer, Phanx. I only searched for "pattern matching" and the like and so I haven't found the other threat. I'll post there then.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » 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