Where do I start when attempting to make something like Markdown?

Hey! I’m trying to create a new version of my custom chat and I want to know if there’s a good way for detecting markdown patterns for strings sent in chat.

Ex: **hi** = hi and ***hi*** = hi both working and even *hi* = hi

And stuff like ~~hi~~ = hi

So basically just does anyone know how I can detect these efficiently in a string and differentiate them since there can be up to 3 asterisks that all mean different things? Any pointers or posts would be very much appreciated! If someone can help me I can potentially pay and 100% credit you on the new version of the chat.

I’m not very experienced with string patterns because they hurt my brain and don’t know where to start.

I’m really bad at explaining it, but some things like this: Basic Syntax | Markdown Guide

Rich text seems to be the easiest solution:
“this is <b>BOLD</b>”
becomes
“this is BOLD
inside a textbox with RichText set to true

so if you want “this is ~~BOLD~~”
to become “this is BOLD

you can use a script replace the 1st ~~ with <b> and 2nd ~~ with </b>

we can simply use string.gsub to replace instances of “~~”. we can also use a variable to keep track of whether we are inside or outside the pattern so we know if we need to replace it with <b> or </b>

we can place it in a loop as follows:

local text = "testing testing testing ~~BOLD~~ testing testing ~~BOLD AGAIN~~" -- our test text
local inside = false
local currenttext,amt =  string.gsub(text,"~~","<b>",1) -- see if theres more stuff
while amt>0 do
	inside = not inside
	if inside == true then
		currenttext,amt = string.gsub(currenttext,"~~","</b>",1)
	else
		currenttext,amt = string.gsub(currenttext,"~~","<b>",1)
	end
end
print(currenttext)

this works with multiple patterns:

local currenttext = "testing **underline** testing ~~BOLD~~ testing testing ~~BOLD AGAIN~~ test ~~**BOLD AND UNDERLINE**~~" -- our test text
local inside = false
currenttext,amt =  string.gsub(currenttext,"~~","<b>",1) -- see if theres more stuff
while amt>0 do
	inside = not inside
	if inside == true then
		currenttext,amt = string.gsub(currenttext,"~~","</b>",1)
	else
		currenttext,amt = string.gsub(currenttext,"~~","<b>",1)
	end
end

local inside = false
currenttext,amt =  string.gsub(currenttext,"%*%*","<u>",1) 
while amt>0 do
	inside = not inside
	if inside == true then
		currenttext,amt = string.gsub(currenttext,"%*%*","</u>",1)
	else
		currenttext,amt = string.gsub(currenttext,"%*%*","<u>",1)
	end

end

print(currenttext)

you may have noticed that i had to put “%” before “*”. this is because it is a “magic” character and has special meanings. we can use “%” to escape it and use it like a normal character. be wary of this.

anyways this is what the string looks like on a textbox with richtext enabled:

oh yeah, for your example, the same logic should apply to differentiating between “***”, “**”, and “*”. you just have to replace the longest pattern first so that the long pattern doesn’t get mistaken for many short patterns.

for example,
you’d replace “***” with <i><b> and </i></b>
then
“**” with <b> and </b>
and finally
“*” with <i> and </i>