我需要一些幫助來創建我的模式。我已經完成了基本部分,但仍有一個問題。Lua模式分離問題
比方說,我有一個字符串,如下所示:
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
:(
任何幫助將不勝感激。
這部分完成了這項工作,但是當某人輸入諸如「00:20:14」之類的東西時,前兩個零就消失了。任何幫助將不勝感激:) – sgtaziz
@ user1773027如果您確定只使用':red:'格式的顏色,那麼您可以使用'(:%a - :)'代替' (:%重量 - :)'。 – hjpotter92
我的解決方案也適用於「00:20:14」 – tanzil