lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Henderson, Michael D wrote:
Okay, I re-read Roberto Ierusalimschy's original post a couple three
times and added an empty string to my return statement. I am not sure
*why* it works, but it does.

Because of the new behavior of gsub, which now accepts a table (and not only a string or function).


local t = {Hello='World', foo='bar'}

1) print(string.gsub('Hello, foo!', '(%w+)', t))
> World, bar

2) print(string.gsub('Mister Anderson, Welcome back', '(%w+)', t))
> Mister Anderson, Welcome back

Note that number 2 didn't had an equivalent key on t, so gsub kept it (in other words: the old behavior would replace all words from the source string to "")