Remove last x lines of string

I want to remove last line of string in Roblox. However the method I am using now is slow and string gets too long (string is too long error) after few uses. The code:

local str = "I will be the last line of string\nI am the last line of string now\n"
local tab = str:split("\n")
for i = 1, 2 do
    table.remove(tab, #tab)
end
print(tab[#tab])

Thanks for help.
Also note that my string always ends with new line.

string.gsub(Text, "([^\n]-)[\n]$", "")

This removes the last line of a string.

I recommend researching string patterns properly.