Malformed pattern (missing ']')

Hi! I’m working on a search bar and i noticed that if someone types a Square bracket or even a normal bracket, i get a bunch of errors such as: malformed pattern (missing ']')

is there any way to detect and prevent this from happening?

code snippet:

SearchBar.Changed:Connect(function()
		for _,button in pairs(ScrollingFrame:GetChildren()) do
			local search = string.lower(SearchBar.Text)
			if button:IsA("ImageButton") then
				if search ~= "" then
					local flagName = string.lower(button.Name)
					
					if string.find(flagName, search) and table.find(buttons,button.Name) then
						button.Visible = true
					else
						button.Visible = false
					end
				else
					if table.find(buttons,button.Name) then
						button.Visible = true
					end
				end
			end
		end
	end)
if string.find(flagName, "\\"..search) ...
1 Like

so, like this?
if string.find(flagName, "\\"..search) and table.find(buttons,button.Name) then

yes the … means u continue ur code its just a replacement u can use backslash \

I did what you said but now my search isnt working, it did fix the problem but when i for example search “luxembourg” it doesnt show up
image

if string.find(string.lower(flagName), string.lower(search)) or string.find(flagName, search)  ...
1 Like

Okay this worked, thank you so much for your time

1 Like

glad that helped! now u can have ur search anywherreee

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.