Thread Tools Display Modes
11-03-15, 10:30 PM   #1
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Matching pattern with words and apostrophes

I'm splitting strings into individual words to create an auto-completion dictionary, but my current code does not account for words with apostrophes in them.
I'd like the dictionary to store combinations such as "doesn't", "let's", etc.

I'm currently using the pattern "[%a][%w]+", which is perfectly fine for coherent words, but will cut words with apostrophes into parts.
__________________

Last edited by MunkDev : 11-04-15 at 12:41 AM.
  Reply With Quote
11-03-15, 10:37 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
"[%a][%w']*[%w]+" should match a word containing an apostrophe.
  Reply With Quote
11-03-15, 10:45 PM   #3
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by semlar View Post
"[%a][%w']*[%w]+" should match a word containing an apostrophe.
Thanks! Works like a charm! Kudos on the quick response, too.
__________________

Last edited by MunkDev : 11-03-15 at 11:12 PM.
  Reply With Quote
11-04-15, 11:52 AM   #4
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Question

Going to keep using this thread for pattern questions.

How can I remove texture sequences from a string?

How do I turn this:
Lua Code:
  1. HELP_OPTIONS_MOVED = "|TInterface\\OptionsFrame\\UI-OptionsFrame-NewFeatureIcon:0:0:0:-1|t  Colorblind and Move Pad options have been moved to the Accessibility section.";
  2. NPE_MAPCALLOUTBASE = "|TInterface\\WorldMap\\WorldMapArrow:28:28|t marks your location.\n\n";

...into this:
Lua Code:
  1. HELP_OPTIONS_MOVED = "  Colorblind and Move Pad options have been moved to the Accessibility section.";
  2. NPE_MAPCALLOUTBASE = " marks your location.\n\n";
__________________

Last edited by MunkDev : 11-04-15 at 11:55 AM.
  Reply With Quote
11-04-15, 12:08 PM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
There might be a better funciton, but this also works:

Lua Code:
  1. local substring = string.gsub("|TInterface\\OptionsFrame\\UI-OptionsFrame-NewFeatureIcon:0:0:0:-1|t  Colorblind and Move Pad options have been moved to the Accessibility section.", "|T.*|t", "")
  2. print(substring)
  Reply With Quote
11-04-15, 12:10 PM   #6
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by Resike View Post
Lua Code:
  1. local string = string.gsub("|TInterface\\OptionsFrame\\UI-OptionsFrame-NewFeatureIcon:0:0:0:-1|t  Colorblind and Move Pad options have been moved to the Accessibility section.", "|T.*|t", "")
  2. print(string)
That simple? Thanks.
__________________
  Reply With Quote
11-04-15, 12:12 PM   #7
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
"|T.-|t" would be better, if you use .* and you have more than one texture in the string it will match everything from the first texture to the last texture and remove the text in between.
  Reply With Quote
11-04-15, 12:14 PM   #8
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by semlar View Post
"|T.-|t" would be better, if you use .* and you have more than one texture in the string it will match everything from the first texture to the last texture and remove the text in between.
Thanks semlar. There should be an extensive resource on pattern matching somewhere. I find the official documentation very confusing, with inconclusive examples. Or, you know, maybe I'm just dumb as hell.
__________________
  Reply With Quote
11-04-15, 12:18 PM   #9
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by MunkDev View Post
There should be an extensive resource on pattern matching somewhere. I find the official documentation very confusing, with inconclusive examples.
http://wow.gamepedia.com/Pattern_matching is a good resource for lua and http://regular-expressions.info/tutorial.html for learning regex in general.
  Reply With Quote
11-04-15, 10:53 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
There is also a tutorial on lua-users.org
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-05-15, 01:57 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
http://wiki.roblox.com/index.php/String_Formatting is the best Lua pattern resource I've found.
__________________
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
11-07-15, 10:15 PM   #12
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Originally Posted by Phanx View Post
http://wiki.roblox.com/index.php/String_Formatting is the best Lua pattern resource I've found.
That's for string.format rather than the pattern matching functions, did you mean to link this page?
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Matching pattern with words and apostrophes

Thread Tools
Display Modes

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