How do I get these string patterns to work properly?

A recurring post from here:

I gotten a sort of pattern to work, but it’s skipping tons of characters without me telling it to.

Here’s an image of what I’m wanting to see with my code:

This is the results that I’m getting:

The codes are very long (and unoptimized, if you want to you can help that as well):

CodeBlock of a Module Script
function CreateGUI:Execute()

	local frame = self.Frame

	local ScriptColors = {

		TextColors = Color3.fromRGB(204,204,204),
		Keywords = Color3.fromRGB(248, 109, 124),
		String = Color3.fromRGB(173, 241, 149),
		Numbers = Color3.fromRGB(255, 198, 0)

	}

	for item, value in ipairs(self.Content) do

		local numItem = item
		local valueType = value

		if valueType:find("scripture: ") then

			local ScriptViewer = ReplicatedStorage.Contents.ScriptViewer:Clone()

			ScriptViewer.Parent = frame

			local scripture = string.gsub(value, "scripture: ", "")
			local lineText = string.split(scripture, "\n")

			print(lineText)

			for lineNumber, lineContent in ipairs(lineText) do
				local lineFrame = ReplicatedStorage.Contents.LineFrame:Clone()

				lineFrame.LineNumber.Text = lineNumber
				lineFrame.Parent = ScriptViewer

				local Keywords = {
					Keyword8 = {'continue', 'function'},
					Keyword6 = {'export', 'repeat', 'elseif'},
					Keyword5 = {'print', 'local', 'while', 'break', 'until'},
					Keyword4 = {'else', 'next', 'then', 'self'},
					Keyword3 = {'for', 'end', 'not', 'and'},
					Keyword2 = {'do', 'or', 'if'}
				}

				local Operators = {'(', ')', '%s?=%s?', '%*', '/', '%%', '%^', '%s?.%s?', '#', '~', '+', '%-', '%$'}

				local doubleQuotation = '%b""'

				local charPos = 1

				while charPos <= string.len(lineContent) do
					wait(0.00000000000000001)
					print(lineContent:sub(charPos))

					if table.find(Keywords.Keyword5, lineContent:sub(charPos, charPos + 4)) then

						local Label = Instance.new("TextLabel")
						local String = lineContent:sub(charPos, charPos + 4)

						Label.Text = String
						Label.TextSize = 27
						Label.AutomaticSize = Enum.AutomaticSize.XY
						Label.Size = UDim2.new(0,2,1,0)
						Label.BackgroundTransparency = 1
						Label.Font = Enum.Font.Code
						Label.TextColor3 = ScriptColors.Keywords
						Label.Parent = lineFrame.TextGoesHere

						local incremsToSkip = String:len()	

						charPos += incremsToSkip

						continue
						
					elseif table.find(Keywords.Keyword4, lineContent:sub(charPos, charPos + 3)) then

						local Label = Instance.new("TextLabel")
						local String = lineContent:sub(charPos, charPos + 3)

						Label.Text = String
						Label.TextSize = 27
						Label.AutomaticSize = Enum.AutomaticSize.XY
						Label.Size = UDim2.new(0,2,1,0)
						Label.BackgroundTransparency = 1
						Label.Font = Enum.Font.Code
						Label.TextColor3 = ScriptColors.Keywords
						Label.Parent = lineFrame.TextGoesHere

						local incremsToSkip = String:len()	

						charPos += incremsToSkip

						continue
						
					elseif table.find(Keywords.Keyword3, lineContent:sub(charPos, charPos + 2)) then

						local Label = Instance.new("TextLabel")
						local String = lineContent:sub(charPos, charPos + 2)

						Label.Text = String
						Label.TextSize = 27
						Label.AutomaticSize = Enum.AutomaticSize.XY
						Label.Size = UDim2.new(0,2,1,0)
						Label.BackgroundTransparency = 1
						Label.Font = Enum.Font.Code
						Label.TextColor3 = ScriptColors.Keywords
						Label.Parent = lineFrame.TextGoesHere

						local incremsToSkip = String:len()	

						charPos += incremsToSkip

						continue
						
					elseif table.find(Keywords.Keyword2, lineContent:sub(charPos, charPos + 1)) then

						local Label = Instance.new("TextLabel")
						local String = lineContent:sub(charPos, charPos + 1)

						Label.Text = String
						Label.TextSize = 27
						Label.AutomaticSize = Enum.AutomaticSize.XY
						Label.Size = UDim2.new(0,2,1,0)
						Label.BackgroundTransparency = 1
						Label.Font = Enum.Font.Code
						Label.TextColor3 = ScriptColors.Keywords
						Label.Parent = lineFrame.TextGoesHere

						local incremsToSkip = String:len()	

						charPos += incremsToSkip

						continue
						
					elseif table.find(Keywords.Keyword6, lineContent:sub(charPos, charPos + 5)) then

						local Label = Instance.new("TextLabel")
						local String = lineContent:sub(charPos, charPos + 5)

						Label.Text = String
						Label.TextSize = 27
						Label.AutomaticSize = Enum.AutomaticSize.XY
						Label.Size = UDim2.new(0,2,1,0)
						Label.BackgroundTransparency = 1
						Label.Font = Enum.Font.Code
						Label.TextColor3 = ScriptColors.Keywords
						Label.Parent = lineFrame.TextGoesHere

						local incremsToSkip = String:len()	

						charPos += incremsToSkip

						continue
						
					elseif table.find(Keywords.Keyword8, lineContent:sub(charPos, charPos + 7)) then

						local Label = Instance.new("TextLabel")
						local String = lineContent:sub(charPos, charPos + 8)

						Label.Text = String
						Label.TextSize = 27
						Label.AutomaticSize = Enum.AutomaticSize.XY
						Label.Size = UDim2.new(0,2,1,0)
						Label.BackgroundTransparency = 1
						Label.Font = Enum.Font.Code
						Label.TextColor3 = ScriptColors.Keywords
						Label.Parent = lineFrame.TextGoesHere

						local incremsToSkip = String:len()	

						charPos += incremsToSkip

						continue
						
					elseif table.find(Operators, lineContent:sub(charPos, charPos)) then

						local Label = Instance.new("TextLabel")
						print(lineContent:sub(charPos, charPos))
						Label.Text = lineContent:sub(charPos, charPos)
						Label.TextSize = 27
						Label.AutomaticSize = Enum.AutomaticSize.XY
						Label.Size = UDim2.new(0,2,1,0)
						Label.BackgroundTransparency = 1
						Label.Font = Enum.Font.Code
						Label.TextColor3 = ScriptColors.TextColors
						Label.Parent = lineFrame.TextGoesHere

						charPos += 1
						continue

					elseif lineContent:match(doubleQuotation, charPos) then

						local texture = lineContent:match(doubleQuotation, charPos)
						local Label = Instance.new("TextLabel")

						print(texture)
						Label.Text = texture
						Label.TextSize = 27
						Label.AutomaticSize = Enum.AutomaticSize.XY
						Label.Size = UDim2.new(0,2,1,0)
						Label.BackgroundTransparency = 1
						Label.Font = Enum.Font.Code
						Label.TextColor3 = ScriptColors.String
						Label.Parent = lineFrame.TextGoesHere
						
						charPos += string.len(texture)
						continue
						
					elseif string.match("%s+(%a+%d*)%s?=%s?", charPos) then

						local Label = Instance.new("TextLabel")
						local text = string.match("%s+(%a+%d*)%s?=%s?", charPos)
						
						print("worked")
						print(text)
						Label.Text = text
						Label.TextSize = 27
						Label.AutomaticSize = Enum.AutomaticSize.XY
						Label.Size = UDim2.new(0,2,1,0)
						Label.Transparency = 1
						Label.Font = Enum.Font.Code
						Label.TextColor3 = ScriptColors.Keywords
						Label.Parent = lineFrame.TextGoesHere

						charPos += text:len()
						continue

					else
						charPos += 1
					end
					charPos += 1
				end
			end

		elseif valueType:find("paragraph: ") then

			local paragraph = string.gsub(valueType, "paragraph: ", "")
			local newParagraph = ReplicatedStorage.Contents.Paragraph:Clone()	

			newParagraph.Text = paragraph
			newParagraph.Parent = frame
		end
	end
end
The script where I execute the functions
local testModule = require(game.ReplicatedStorage.ModuleScript)

local new = testModule.SetMainPage(script.Parent.Parent.Parent.Parent.InformationHere.Content)

-- ...
new:Scripture(
	[[print("Hello World!")
local Test = print("We're testing again")]]
)
new:Execute()

And finding out the root of the problem, it’s skipping the %sText%s=%sprint( entirely.

The output:

14:25:05.952  local Test = print("We're testing again")  -  Client - ModuleScript:88
  14:25:05.999   Test = print("We're testing again")  -  Client -  ModuleScript:88     -- This is the start of where it did a huge skip
  14:25:06.000  "We're testing again"  -  Client - ModuleScript:231     -- This is the end of where it did that huge skip
  14:25:06.038  testing again")  -  Client - ModuleScript:88
  14:25:06.069  sting again")  -  Client - ModuleScript:88
  14:25:06.117  ing again")  -  Client - ModuleScript:88
  14:25:06.150  g again")  -  Client - ModuleScript:88
  14:25:06.204  again")  -  Client - ModuleScript:88
  14:25:06.265  ain")  -  Client - ModuleScript:88
  14:25:06.304  n")  -  Client - ModuleScript:88
  14:25:06.343  )  -  Client - ModuleScript:88
  14:25:06.344  )  -  Client - ModuleScript:213

idk much about string patterns but I guess you can see these

A, B, C, D, E