WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Matching pattern with words and apostrophes (https://www.wowinterface.com/forums/showthread.php?t=52858)

MunkDev 11-03-15 10:30 PM

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.

semlar 11-03-15 10:37 PM

"[%a][%w']*[%w]+" should match a word containing an apostrophe.

MunkDev 11-03-15 10:45 PM

Quote:

Originally Posted by semlar (Post 311649)
"[%a][%w']*[%w]+" should match a word containing an apostrophe.

Thanks! Works like a charm! Kudos on the quick response, too. :p

MunkDev 11-04-15 11:52 AM

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";

Resike 11-04-15 12:08 PM

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)

MunkDev 11-04-15 12:10 PM

Quote:

Originally Posted by Resike (Post 311658)
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.

semlar 11-04-15 12:12 PM

"|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.

MunkDev 11-04-15 12:14 PM

Quote:

Originally Posted by semlar (Post 311660)
"|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.

semlar 11-04-15 12:18 PM

Quote:

Originally Posted by MunkDev (Post 311662)
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.

Seerah 11-04-15 10:53 PM

There is also a tutorial on lua-users.org

Phanx 11-05-15 01:57 PM

http://wiki.roblox.com/index.php/String_Formatting is the best Lua pattern resource I've found.

Choonstertwo 11-07-15 10:15 PM

Quote:

Originally Posted by Phanx (Post 311676)
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?


All times are GMT -6. The time now is 07:43 AM.

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