I'm trying to make a "Find in page" feature, like the one in Google but it's for a string. I tried to use string.gsub(), but it replaced all the matches.
How can I make it so that it only removes 1 match?
Code so far:
local s = "this is a text string"
local function find(s, matchingString)
s = s:lower()
matchingString = matchingString:lower()
local _, matches = string.gsub(s, matchingString, matchingString)
if matches == 1 then
after = " match"
elseif matchingString == "" then
print("0 matches")
return
else
after = " matches"
end
print(matches..after)
if matches > 0 then
for i = 1, matches do
local a, b = s:find(matchingString)
s = s:gsub(matchingString, "")--what can I change this to so that it only removes 1 match
print(s)
print("Location of match "..i..": "..a..", "..b)
end
end
end
find(s, "a")

1 comment
Thank you! I looked on the dev hub and it only had 3 arguments. They should update it