KB97
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 683 |
|
|
| 07 Nov 2011 04:57 PM |
Using gmatch, I'm trying to 'split' a string into its individual words, keep the symbol prefixes, and words contained in brackets are kept as a whole, so that this string:
"/slash word @symbol [multiple word input] #[with symbol]"
Would result in these captures:
/slash word @symbol [multiple word input] #[with symbol]
I have some experience with string manipulation, but I haven't found a way to do this. |
|
|
| Report Abuse |
|
|
|
| 07 Nov 2011 04:58 PM |
for word in STRING:gmatch("%a+") do print(Word) end |
|
|
| Report Abuse |
|
|
KB97
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 683 |
|
|
| 07 Nov 2011 05:00 PM |
| "... and words contained in brackets are kept as a whole ..." |
|
|
| Report Abuse |
|
|
|
| 07 Nov 2011 05:00 PM |
Oops.
for word in STRING:gmatch("%p%a+") do print(word) end |
|
|
| Report Abuse |
|
|
KB97
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 683 |
|
|
| 07 Nov 2011 05:54 PM |
| Thanks for trying, but that's not what I need. Read the whole post. |
|
|
| Report Abuse |
|
|
DXPower
|
  |
| Joined: 21 Oct 2008 |
| Total Posts: 2866 |
|
|
| 07 Nov 2011 05:56 PM |
Um.... Try separating them using %s.
I'm not that good with strings. |
|
|
| Report Abuse |
|
|
KB97
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 683 |
|
| |
|
KB97
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 683 |
|
| |
|
KB97
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 683 |
|
| |
|
KB97
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 683 |
|
| |
|
KB97
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 683 |
|
| |
|
|
| 07 Nov 2011 11:50 PM |
Its not gmatch, but here it goes...
s = "/slash word @symbol [multiple word input] #[with symbol]"
pattern = "(%p%a+)%s(%a+)%s(%p%a+)%s(%p.-%p)%s(%p%p.-%p)"
Start, End, First, Second, Third, Fourth, Fifth = string.find( s, pattern ) print(First) print(Second) print(Third) print(Fourth) print(Fifth)
|
|
|
| Report Abuse |
|
|
KB97
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 683 |
|
|
| 08 Nov 2011 03:18 PM |
Thanks, but that isn't what I need.
The string being 'split' is a chat message, and the words and positions of brackets and symbols are just for testing purposes. They won't be consistent in length, position or context in actual use. |
|
|
| Report Abuse |
|
|
KB97
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 683 |
|
| |
|