lua5.1 / lua5.2 console (from ubuntu packages):
Lua Code:
function df(...) print(string.format(...)) end
df("%q %d", string.gsub("une rune de puissance", "^(%l+) ", {une="<une>", de="<de>"}))
output:
Code:
"<une>rune de puissance" 1
This is correct output. The pattern "^(%l+) " is supposed to match a lower-case word and a space at the start of the string, and if that word is a key in the table ("une" or "de"), replace it with the corresponding value from the table. There's one such word, and the function makes 1 replacement.
lua5.1* in ESO:
Lua Code:
/script df("%q %d", string.gsub("une rune de puissance", "^(%l+) ", {une="<une>", de="<de>"}))
output:
Code:
"<une>rune <de>puissance" 3
This is incorrect. First, the function replaces "de" that is not at the start of the string. Second, it says it made 3 replacements.
Edit: minor correction. The second value returned from gsub is the number of matches, not the number of replacements (words that match but are not in the table are not replaced). Of course 3 is still wrong, as there should be only 1 match.