itme93
itme93

Reputation: 39

Way to seprate each word from string and include special characters lua

So I recently used this following lua code to separate each word from string and notice it's not showing special characters (e.g. /,;,'). So is there anyway for it to show?

string = "Test, Im testing"
for word in string:gmatch("%w+") do
print(word)
end

This code will not show the commas on the string but I need it to show.

Upvotes: 1

Views: 106

Answers (1)

hjpotter92
hjpotter92

Reputation: 80657

Instead of %w I think you are looking for %S pattern.

Alternatively you can also try [%w%p]+.

See a brief description of how lua pattern behave at lua pil

Upvotes: 3

Related Questions