我需要一些帮助来创建我的模式。我已经完成了基本部分,但仍有一个问题。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