Find string between tags not working

98 views Asked by At

I have this string

str="[COLOR r;255|g;255|b;0]  1 | Someoneelse       | 8000     |    0 |    0 |    0[/COLOR][ENTER]  2 | Expendables  | 4000     |    0 |    0 |    0[ENTER]  3 | Extra   | 2000     |    0 |    0 |    0[ENTER]  4 | Extraordinry  | 0        |    0 |    0 |    0"

and I want to return all between [COLOR r;255|g;255|b;0] and [/COLOR]

I try it but, it doesn't work

print(string.find(str,"[COLOR r;255|g;255|b;0](.-)[/COLOR]"))
2

There are 2 answers

0
Yu Hao On BEST ANSWER

Try:

print(string.match(str,"%[COLOR r;255|g;255|b;0%](.-)%[/COLOR%]"))

Note that [,] are magic characters, so they need to be escaped.

0
Yo Crus Salazar On

iam solved it

string.gfind(str,"%[COLOR r;255|g;255|b;0](.-)%[/COLOR]")()