Malformed pattern (missing ']')?

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to make a function that searches a script for strings and then prints the string table
  2. What is the issue? Include screenshots / videos if possible!
    An error occurs at:
local ind3 = string.find(tx, '[[', i)
Image

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried putting "\"s but it showed an error instead of a warning

Here is the script so far (unfinished):

local function get(tx)
	local i = 1
	local occ = {}
	for i = 1,1e6 do --"for i = 1, 1e6" do only for testing. Change to "while true do"
		local ind = string.find(tx, "'", i)
		local ind2 = string.find(tx, '"', i)
		local ind3 = string.find(tx, '[[', i)
		if ind or ind2 then
			if ind then
				table.insert(occ, 1, ind)
				i = ind + 1
			else
				table.insert(occ, 1, ind2)
				i = ind2 + 1
			end
		elseif ind3 then
			local ind4 = string.find(tx, ']]', ind3)
			if ind4 then
				table.insert(occ, 1, {ind3,ind4})
				i = ind3 + 1
			end
		else break end
	end
	print(occ)
end
1 Like

Do this:

string.find(tx, "%[%[", i)

and

string.find(tx, "%]%]", i)

Incase anyone stumbles upon this in the future. The reason why this worked is because string.find uses a string pattern. The % tells the system that this is not part of a pattern and is just a regular character.

3 Likes

Error fixed. Thanks for the help