GMatch?

Hey! I don’t understand patterns so could someone help me?

I have table:


Colors = {
    red = Color(255, 0, 0, 255)
}

And chatbox and i want when someone types :SOMETHING: then it would check if inside is the tables “red”.

Thank you.

-snip misread the question-
I don’t understand what you mean.
Are you trying to get the color from the table or checking a part of a string?

If i write :red: i want it to detect the “red” part and check if it is in the table Colors.

Colors.red should return that color.

… I mean i need to get the word BETWEEN :: first. I dont know how to do that thats why this is GMatch and i need pattern to get it.

[lua]local colors = {
[“red”] = Color(255, 0, 0),
[“white”] = Color(255, 255, 255)
}

local pattern = “%[%w+%]”
local test = “yo buddy look at my jacket [white]!”

for match in test:gmatch( pattern ) do
local tagstart, tagend = test:find( match, 0, true )
– what character tags starts at and ends at
end[/lua]

This probably sucks since I am not very good at string patterns, but it works at least.

I was hoping so much that this would be a gmod dating thing…

Are you lonley?

Heavy use of the dumb rating incoming.

For future reference - pattern captures is how you properly do it: http://www.lua.org/pil/20.3.html

Use %b:: to match :stuff: like that. It’s easier and will match stuff properly if its inside like ::red: :blue::