パターンの作成に助けが必要です。基本的な部分はできましたが、問題が 1 つあります。
次のような文字列があるとしましょう。
John: I can type in :red:colour! :white:Not in the same :red:wo:green:rd :white:though :(
色を実際の値から分離するために、次のコードを設定しています。
line = "John: I can type in :red:colour! :white:Not in the same :red:wo:green:rd :white:though :("
for token in string.gmatch(line, "%s?[(%S)]+[^.]?") do
for startpos, token2, endpos in string.gmatch(token, "()(%b::)()") do
print(token2)
token = string.gsub(token, token2, "")
end
print(token)
end
出力します:
John:
I
can
type
in
:red:
colour!
:white:
Not
in
the
same
:red:
:green:
word
:white:
though
:(
印刷したいとき:
John:
I
can
type
in
:red:
colour!
:white:
Not
in
the
same
:red:
wo
:green:
rd
:white:
though
:(
どんな助けでも大歓迎です。