我正在做一個JavaScript插件,在每個頁面加載時啓動,用鏈接替換每個匹配結構...該鏈接重定向到Web應用程序/數據庫。刀片遊戲的編碼器的資源。創建一個匹配python元組結構的正則表達式
理論上很簡單,但我發現了一條成功之路上的巨大障礙:正則表達式。
即使有一個名爲QuickRegex的程序的幫助,我無法得到匹配的結構。或者如果我沒有做適當的調節,它會輸出錯誤的結果。匹配結構如下:
(item_set_slot, "itm_heavy_crossbow", slot_item_multiplayer_item_class),
我要挑item_set_slot
,並把它變成一個鏈接到http://mbcommands.ollclan.eu/#$1
這是我使用的代碼,這樣的作品,或多或少。 ;)
/* Mount&Blade Command Database Linking by Swyter */
function swymbcommandshooker(){
/* Regular HTML Expressions */
document.getElementsByTagName("body")[0].innerHTML=document.getElementsByTagName("body")[0].innerHTML.replace(/[\(]([a-zA-Z_]+)[\,]/gi, "(<a href='http://mbcommands.ollclan.eu/#$1' title='[?] Take an look in the Command Database' target='_blank'>$1</a>,");
/* Python highlighter Support...*/
document.getElementsByTagName("body")[0].innerHTML=document.getElementsByTagName("body")[0].innerHTML.replace(/(</span>([_a-z]+)\,/gi, "(</span><a href='http://mbcommands.ollclan.eu/#$1' title='[?] Take an look in the Command Database' target='_blank'>$1</a>,");
}
addOnloadHook(swymbcommandshooker);
在此先感謝。
如果它起作用,'或多或少',那麼問題是什麼? – Ikke 2011-03-24 10:23:23
我想找到一個完整覆蓋結構的正則表達式。當前代碼比真正的解決方案更具破壞性...... – Swyter 2011-03-24 12:01:05
是否存在無法在Python標準庫中使用JSON序列化程序/反序列化程序的特定原因,以及節省一些麻煩? – ssokolow 2011-03-24 13:40:34