2
我一直在Lua中編寫一個程序,可以自動格式化角色扮演中的IRC日誌。在角色扮演日誌中,有一個針對「不符合角色」對話的具體指導原則,我們使用雙括號。例如:((<Things unrelated to roleplay go here>))
。我一直試圖讓我的程序刪除雙括號(包括括號)之間的文本。該代碼是:Lua模式幫助(雙括號)
ofile = io.open("Output.txt", "w")
rfile = io.open("Input.txt", "r")
p = rfile:read("*all")
w = string.gsub(p, "%(%(.*?%)%)", "")
ofile:write(w)
這裏的模式是>"%(%(.*?%)%)"
我已經試過圖案的多種變化。所有導致無果而終的結果:
1. %(%(.*?%)%) --Wouldn't do anything.
2. %(%(.*%)%) --Would remove *everything* after the first OOC message.
然後,我的朋友告訴我,用百分比前面加上括號是行不通的,而我不得不用反斜槓「逃離」的括號。
3. \(\(.*\)\) --resulted in the output file being completely empty.
4. (\(\(.*\)\)) --Same result as above.
5. (\(\(.*?\)\) --would for some reason, remove large parts of the text for no apparent reason.
6. \(\(.*?\)\) --would just remove all the text except for the last line.
短,絕對的問題: 我需要使用去除雙括號之間的所有文本,並刪除雙括號自己太什麼模式?
這些是正則表達式,而不是設計模式。 – 2014-11-24 14:54:20