Finding <> in a string

I’m tryna find an easy way to look for <> in a string (trying to make my own RichText module) This is what I got an it kinda works, but I feel there has to be a nicer way to put it

local text = "Hello <Font=Gotham> World!"
local finalText = ""

for i = 1, text:len() do
	if string.sub(text, i, i) == "<" then
		if string.sub(text, i + 1, i + 4) == "Font" then
			print("Font changing to")
		elseif string.sub(text, i + 1, i + 5) == "Color" then
			print("Color changing to")
		end
	end
end

I want an easier way to look for where a < starts and then find where > is (end) then get the key word (Font, Color, etc) and then be able to see what value is given after)

Notes

  1. I know of Defaultio’s RichText module. I wanna make my own though
  2. Roblox’s RichText is still heavily unreliable (does not scale / does not work with a typewriter effect)

Try using string patterns. %b<> should work for this.

2 Likes