I have this string, bind V "echo \"this is a test\" (0, 100, 255)" | blah
And I’m trying to get the whole substring. I want it to look like this: bind V _ | blah
And I’m using this simple string pattern, string.gsub(str, "%b\"\"", function(match) substr = match return "_" end)
However, that doesn’t capture the substring correctly. I’ve tried modifying the string pattern and whatnot, and I’ve had no luck. I don’t know how to do this.
i actually made something that “bypasses” the backlash.
local myStr = 'bind V "echo \"this is a test\" (0, 100, 255)" | blah'
local function GetTicks(str,tab,index)
tab = tab or {}
local var,_ = string.find(str,'"',index or 0)
if var then
table.insert(tab,var)
return GetTicks(str,tab,var+1)
else
return tab
end
end
local function gsub2(str,replacement)
local Ticks = GetTicks(str)
local charArray = myStr:split("")
local fus1 = str:sub(1,Ticks[1]-1)
local fus2 = str:sub(Ticks[#Ticks]+1,#str)
return fus1..replacement..fus2
end
local newstr = gsub2(myStr,"_")
print(newstr) -- bind V _ | blah
There is probably other way but thats what i came up with
local Subject = 'bind V "echo \"this is a test\" (0, 100, 255)" | blah'
local Result = string.gsub(Subject, "[^\\]\".*\"[^\\]", " _ ")
print(Result) --bind V _ | blah