Jump to content




string.gmatch() help


  • You cannot reply to this topic
2 replies to this topic

#1 HurricaneCoder

  • Members
  • 52 posts

Posted 08 June 2013 - 11:28 PM

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()?

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 08 June 2013 - 11:32 PM

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

#3 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 08 June 2013 - 11:33 PM

To capture anything not a space, try "%S+" or "([^%s]+)".







2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users