Module:ReplaceLastVowel

local export = {}

function export.replace_last_vowel(text, replace) -- The pattern to match the last vowel in the string local pattern = "[aeiouyáéíóúAEIOUYÁÉÍÓÚ]([^aeiouyáéíóúAEIOUYÁÉÍÓÚ]*)$" -- Find the last vowel in the text local vowel = string.match(text, pattern) -- If there is a vowel, replace it with the specified string if vowel then local index = string.len(text) - string.len(vowel) + 1 text = string.sub(text, 1, index - 1) .. replace .. string.sub(text, index + 1) end -- Return the modified text return text end

return export