How to use patterns to actually make your own Markup Language?

Well as the title states I want to do my own Markup language(things like <red></red> will make everything red inbetween them!)
So I tried to do my own testing etc looked on some lua pattern tutorials only, I dont get it work. Here is what I try:

	local s = string.gmatch("<_blue_> Unknown </_blue_> " , "<_%a_>%a</_%a_>")

It prints out nothing. Does someone got an idea?

if it doesn’t need to cascade, you can use patterns, use string.gsub
however, if you need them to cascade, you need a more complex parser

string.gmatch returns an iterator to be used with “for” btw

local start,arg,finish = string.match("<_blue_>test :P</_blue_>" ,"<_([%w]+)_>([%w%s%p]*)</_([%w]+)_>")

test :P

omg, That shows how I suck at patterns. I still dont get it :open_mouth:

nice, but you want to make sure you get the matching closing tag, not just any of them:
[lua]local tag,arg = string.match("<blue>test :P</blue>" ,"<([%w]+)>([%w%s%p]*)</%1>")

test :P[/lua]

I got caught up a bit and made this:
[lua]local text = “foo <blue>test :P</blue> bar”

local function Color(r,g,b)
return { r = r, g = g, b = b }

local tags = {
red = Color(255,0,0),
green = Color(0,255,0),
blue = Color(0,0,255),
defaultcolor = “Color(255,255,255)”

local output = { “chat.AddText(”…defaultcolor…", " }
local last = 1
for before,tag,arg,after in text:gmatch("()<([%w]+)>([%w%s%p]*)</%2>()") do
textbefore = text:sub(last, before-1)
last = after

c = tags[tag]
if c then
	-- a color for this command was found =&gt; display it.
	table.insert(output, string.format("%q, Color(%d,%d,%d), %q, %s, ", textbefore, c.r,c.g,c.b, arg, defaultcolor))
	-- command not found =&gt; display literally
	table.insert(output, string.format("%q, ", text:sub(last, after-1)))


table.insert(output, string.format("%q)",text:sub(last)))

– output: chat.AddText(Color(255,255,255), "foo “, Color(0,0,255), “test :P”, Color(255,255,255), " bar”)[/lua]

EDIT: fixed a small mistake

Nvm, TomyLobo got a nice example for colored chat.