[Fixed] Error saying malformed pattern [Only gets first keyword]

I’m not sure on this one, is it really ment to error? It still works though.
if Input.Text:find(BannedKeyWords) then

-- Game Services --
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local StarterGui = game:GetService('StarterGui')
local GuiService = game:GetService('GuiService')
local Players = game:GetService('Players')
local LocalPlayer = Players.LocalPlayer -- Gets Player locally (Client).
local Camera = workspace.CurrentCamera -- CurrentCamera

-- Variable --
local Main = script.Parent.Parent.Parent:WaitForChild("Main")
local LoginBox = Main:FindFirstChild('LoginBox')
local Admin = LoginBox:FindFirstChild('Admin')
local LoginButton = LoginBox:WaitForChild('LoginButton')
local Input = LoginBox.BoxFrame:FindFirstChild('Input')

-- Modules --
local ButtonView = require(ReplicatedStorage:WaitForChild('ButtonView'))

-- Main Script --

ButtonView:hover(Admin)
ButtonView:hover(LoginButton)

StarterGui:SetCore('TopbarEnabled',false)
Main.Visible = true


-- Tables and Functions --

local ListOfBannedAndCursedWords = {'Bad', 'Gay', 'FREEROUX', 'Spam', 'Noob', 'WE_HATE_ROBLOX'} -- Don't let anybody read these words. It's to prevent bad language from being putted in.
local ListOfNegativeUnacceptedWordsResponse = {'Please try again.', 'Login info is inappropriate.', 'Error, If this error happens again. Please contact an administrator or a Developer.', 'Bad reques', 'Try again later.'} -- If the password is not accepted and finds to be inappropriate.
local ListOfBannedKeyWords = {'!', '%', '*'}

function SetCamera(FacePosition)
	Camera.CameraType = 'Scriptable'
	Camera.CameraSubject = FacePosition
	Camera.CoordinateFrame = CFrame.new(FacePosition.Position)
end

function Login(Register, IsTyping)
	Input:GetPropertyChangedSignal('Text'):Connect(function()
	Register.MouseButton1Click:Connect(function()
			if Input.Text == LocalPlayer.Name then
				script.Parent.Parent.Parent.Parent:FindFirstChild('MainGui'):Destroy()
				StarterGui:SetCore('TopbarEnabled',true)
				Camera.CameraType = 'Custom'
				Camera.CameraSubject = LocalPlayer.Character
				else
				for _,ListOfBannedWords in ipairs(ListOfBannedAndCursedWords) do
					if Input.Text:find(ListOfBannedWords) then
						LocalPlayer:Kick("Don't use inappropriate usernames!")
				end
					for _,BannedKeyWords in ipairs(ListOfBannedKeyWords) do
						if Input.Text:find(BannedKeyWords) then
						Input.Text = ("Special keywords are not allowed.")
						Input.TextColor3 = Color3.fromRGB(182, 37, 37)
						delay(2,function()
							Input.Text = ""
							Input.TextColor3 = Color3.fromRGB(0,0,0)
							end)
						end
						end
					end
		end
	end)
		end)
	end

-- Connectors --

  SetCamera(workspace:WaitForChild('Baseplate'))
  Login(LoginButton)
  
  
  

Edit to add: @Blokav’s answer is better, and my escaping was incorrect for Lua.

Lua’s string.find takes a regular expression, not an exact string to match. Since the asterisk (*) has special meaning in a regular expression, you’ll need to escape it to say to simply find the character asterisk.

local ListOfBannedKeyWords = {'!', '%', '\\*'}

local ListOfBannedKeyWords = {'!', '%%', '%*'}
1 Like

could somebody find me an example script? yes i think i know of a regular expression but could somebody send me a script with examples?

now this one is a trouble finder, I now put all the keywords in one string and it only finds the first letter

A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain “find substring” operation, with no characters in pattern being considered “magic”.

So your if statements should be:

if Input.Text:find(ListOfBannedWords, 1, true) then

and

if Input.Text:find(BannedKeyWords, 1, true) then

2 Likes

That’s not actually how it works in Lua. Lua doesn’t use the standard regex format like most other languages; it uses its own system of string patterns. The correct way to escape an asterisk would be "%*".

3 Likes