Quantcast string.gsub help - WoWInterface
Thread Tools Display Modes
12-22-12, 09:54 PM   #1
A Murloc Raider
Join Date: Dec 2012
Posts: 9
string.gsub help

Hello, help me with regular expressions.
How to make that at the beginning of the word and after each 3 symbols was "!" ?

Example: !Hel!lo !Wor!ld. !Tes!t !lua!.


Last edited by Starix : 12-22-12 at 09:57 PM.
  Reply With Quote
12-23-12, 12:46 AM   #2
A Pyroguard Emberseer
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,732
I can see this as a series of 3 string.gsub() calls:
("Hello World. Test lua."):gsub("(%S%S%S)","%1!"):gsub("(%s)(%S)","%1!%2"):gsub("^(%S)","!%1");
The first call processes splitting the words into groups of 3 letters separated by "!". This needs to be done first as the other replacements will screw up the grouping pattern. The second pattern handles the start of words by inserting the separator between any occurrence of a space followed by a non-space. The third handles an exception that would rise when the string starts with a non-space character.
ESOUI AddOns | 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 » string.gsub help

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