(Sorry for my broken English)
What I'm trying to do is matching a word (with or without numbers and special characters) or whitespace characters (whitespaces, tabs, optional new lines) in a string in Lua.
For example:
local my_string = "foo bar"
my_string:match(regex) --> should return 'foo', ' ', 'bar'
my_string = " 123!@." -- note: three whitespaces before '123!@.'
my_string:match(regex) --> should return ' ', ' ', ' ', '123!@.'
Where regex
is the Lua regular expression pattern I'm asking for.
Of course I've done some research on Google, but I couldn't find anything useful. What I've got so far is [%s%S]+
and [%s+%S+]
but it doesn't seem to work.
Any solution using the standart library, e.g. string.find
, string.gmatch
etc. is OK.