I highly don’t rely on anybody understanding the purpose or process of this function, so I’ll do my best to explain the piece I’d rather focus on. For those who have knowledge in String Patterns, this would probably be easy for you to grasp: I’m not sure if I’m just during stupid somewhere in the piece I’m having trouble with, or this truly is a problem, but what I’m trying to do here is cut off a piece from a String if it’s equivalent to anything In the array prohibited.
I’m using a gmatch to iterate through the String’s words, I’m trying to accomplish stripping out something if it’s not entieraly just apart of the word; apart of another E.g. “Hello there”, then remove that chunk, it doesn’t seem to work, though if I had the prohibited word equal to the exact, then it would’ve been able to remove it perfectly fine. Yet it doesn’t function properly for both transactions now, what have I done wrong?
String = "Some sentence here I guess?"
local prohibited = {"I guess"} --// or “guess”
function rewrite(String)
local reString = {}
if (String:match("[%w%p]+")) then
for a in String:gmatch("[^%s]+") do
for _,b in next, prohibited do --// function begins here
if (a:find(b) or String:find(b)) then
a = String:gsub(b, "") or a:gsub(b, "")
break
end
end
table.insert(reString, a); --// ends here
end
else return "empty"
end
return table.concat(reString, " ")
end
local rewritedstring = rewrite(String)
if (rewritedstring ~= "empty") then
print("String: '"..rewritedstring.."' - ('"..String.."')")
else return end
--// function is supposed to return the String cleaned up with the prohibited word(s) removed, the String is return normal without the word(s) removed at all.
again, this is going to be incredibly hard to understand if you don’t have a good knowledge of String Patterns, or I’m dumb and there’s something obvious, gl?;)
Extraction of a single word is functional now

2 comments
what is your expected output from the example given above?
It literally says it.. but for closure, it should look like so: ‘Some sentence here ?’ -> ‘I guess’ removed