This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HurricaneCoder's profile picture

string.gmatch() help

Started by HurricaneCoder, 08 June 2013 - 10:28 PM
HurricaneCoder #1
Posted 09 June 2013 - 12:28 AM
So I wrote a program that uses string.gmatch(). So first I define a variable text = "Number_Star" and t = {} then I do for word in string.gmatch(text,"%w+") do table.insert(t,word) end what happen is that this end up splitting. So instead of being t[1] = "Number_Star" it is now t[1] ="Number" and t[2] = "Star". I was wondering is there away to connect them through string.gmatch() or is there a way to disable these special char "_" in read()?
Kingdaro #2
Posted 09 June 2013 - 12:32 AM
You can have character groupings using []. Instead of matching with the string "%w+", you would do "[%w_]+", meaning "one or more matches of any letter or digit, or an underscore."
MudkipTheEpic #3
Posted 09 June 2013 - 12:33 AM
To capture anything not a space, try "%S+" or "([^%s]+)".