Reputation: 55
Anyone knows or have idea how to remove all characters after last occurrence of white space in LUA, for example
foo = "This is some string"
to get
bar = "This is some"
Upvotes: 1
Views: 3342
Reputation: 72312
Try
bar = foo:gsub("(.*)%s.*$","%1")
The pattern greedily captures everything until a whitespace is seen and discards the rest of the string. The key point here is greedily, which has the effect of finding the last whitespace.
Upvotes: 2