local data_string = "Substring removing"
-- By position: keep the head, then the tail
local head = data_string:sub(1, 9)
-- head = Substring
local tail = head:sub(4)
-- tail = string
-- By text: $ pins the match to the end
local no_suffix =
data_string:gsub(" removing$", "")
-- no_suffix = Substring
-- ^ pins it to the start
local no_prefix = no_suffix:gsub("^Sub", "")
-- no_prefix = string
-- From the middle: only the first match
local marked = "Substring removing!"
local middle = marked:gsub(" removing", "", 1)
-- middle = Substring!
print("head = " .. head)
print("tail = " .. tail)
print("no_suffix = " .. no_suffix)
print("no_prefix = " .. no_prefix)
print("middle = " .. middle)