What is the string pattern for a space? Like, the space the spacebar types?
Is there a pattern that does JUST the spacebar?
My goal is to print each word in a sentence, but the word I'm
gets split up into I
and m
when I try "%a+"
:
1 | for w in string.gmatch( "I'm filling out a job application." , "%a+" ) do |
2 | print (w) |
3 | wait() |
4 | end |
I would appreciate any replys. Thanks!
I normally use a pattern trick for those things. You can also check for "not patterns".
In this case you want to match any sequence of characters which is NOT a space.
A space pattern is btw just " ". The %s pattern also matches \n (newline) and some more "white space characters"
The pattern I would use is "[^ ]+". This matches any sequence which is NOT a space. A [] pattern defines a set of characters. If this set stats with a ^ it means NOT that set. In this case we check for non-spaces.
Output:
01 | for w in string.gmatch( "I'm filling out a job application." , "[^ ]+" ) do |
02 | print (w) |
03 | -- There is no need to wait in this case. |
04 | -- wait() |
05 | end |
06 | --[[Output: |
07 | I'm |
08 | filling |
09 | out |
10 | a |
11 | job |
12 | application |
13 | --]] |