2016-04-24 92 views
0

在過去的幾天(幾周,幾個月,幾年,如果你算我的一次又一次的搜索和嘗試)我一直在努力或找到一個正則表達式過濾器可以幫助我刪除在我的代碼中找到的所有多餘的括號。需要幫助,使RegExp過濾器,以取代冗餘括號

附加了正則表達式過濾器必須處理的最壞情況。由於是最好的情況下

回報((((((((((((((((((((((((((getHumanReadableLine( 「avHardwareDisable」)+ getHumanReadableLine(「hasAccessibility 「))+ getHumanReadableLine(」hasAudio「))+ getHumanReadableLine(」hasAudioEncoder「))+ getHumanReadableLine(」hasEmbeddedVideo「))+ getHumanReadableLine(」hasIME「))+ getHumanReadableLine(」hasMP3「))+ getHumanReadableLine(」hasPrinting「)) )+ getHumanReadableLine(「hasStreamingVideo」))+ getHumanReadableLine(「hasTLS」))+ getHumanReadableLine(「hasVideoEncoder」))+ getHumanReadableLine(「hasScreenBroadcast」))+ getHumanReadableLine(「hasScreenPlayback」))+ getHumanReadableLine getHumanReadableLine(「isDebugger」))+ getHumanReadableLine(「language」))+ getHumanReadableLine(「localFileReadDisable」))+ getHumanReadableLine(「manufacturer」))+ getHumanReadableLine(「o ())+ getHumanReadableLine(「screenResolutionX」))+ getHumanReadableLine(「screenResolutionY」)+ getHumanReadableLine(「pixelAspectRatio」))+ getHumanReadableLine(「playerType」))+ getHumanReadableLine(「screenColor」)) ))+ getHumanReadableLine(「version」)));

return(((((name +「:」)+ Capabilities [name])+「\ n」));

正如你所看到的......有一些......我的代碼中有多餘的括號。一直在積極與這些工作很長一段時間,但一直試圖清理我遇到的並試圖找到一個更快的方式來做到這一點。

因此,「乾淨」代碼看起來如何的一個例子,我希望至少!

return(name +「:」+ Capabilities [name] +「\ n」);

return name +「:」+ Capabilities [name] +「\ n」;

任一個是可以接受的,只要完全誠實的代碼本身不嘲笑和更改它是如何工作的。

我非常感謝任何人可以給我的答案。請不要模擬我所做或想要實現的目標。我沒有太多的工作與正則表達式或之前類似的事情......

而只是爲了幽默,你......這裏是我的「正規」我的「乾淨」的例子

(返程)({1 ,}(([^)] {1,}))({1,}))({1,})){1,}

$ 1 $ 2 $ 3 $ 4 //輸出

oh ...忘了提及

(!(testCrossZ()))

可能會出現有時,但這些都不是一個手動清理的問題,如果需要的話。

P.S ...有很多冗餘括號出現......很可能有成千上萬...最有可能是成千上萬。

回答

1

不知道是否適用於動作,但對Java,你可以這樣做:Main Menu | Analyze | Run Inspection by Name | type "parentheses" | select "Unnecessary parentheses" | run in the whole project and fix all problems

結果:

return getHumanReadableLine("avHardwareDisable") + getHumanReadableLine("hasAccessibility") 
    + getHumanReadableLine("hasAudio") + getHumanReadableLine("hasAudioEncoder") 
    + getHumanReadableLine("hasEmbeddedVideo") + getHumanReadableLine("hasIME") 
    + getHumanReadableLine("hasMP3") + getHumanReadableLine("hasPrinting") 
    + getHumanReadableLine("hasScreenBroadcast") + getHumanReadableLine("hasScreenPlayback") 
    + getHumanReadableLine("hasStreamingAudio") + getHumanReadableLine("hasStreamingVideo") 
    + getHumanReadableLine("hasTLS") + getHumanReadableLine("hasVideoEncoder") 
    + getHumanReadableLine("isDebugger") + getHumanReadableLine("language") 
    + getHumanReadableLine("localFileReadDisable") + getHumanReadableLine("manufacturer") 
    + getHumanReadableLine("os") + getHumanReadableLine("pixelAspectRatio") 
    + getHumanReadableLine("playerType") + getHumanReadableLine("screenColor") 
    + getHumanReadableLine("screenDPI") + getHumanReadableLine("screenResolutionX") 
    + getHumanReadableLine("screenResolutionY") + getHumanReadableLine("version"); 
+0

這是一個不適用於動作腳本的java過濾器... – Kithi

+0

我很肯定IntelliJ在Actionscript代碼中查看它時顯示不必要的括號,如果你沒有禁用檢查。我認爲有一種方法可以針對整個文件發生的問題調用修復程序,如果不是該項目的話。我會盡快檢查並提供更多信息。 (您使用的是哪個版本的IntelliJ?) – karfau

0

老實說,我不明白你想要的輸出格式的具體形式,但根據初學者至少清除不必要的括號可以使用純JavaScript完成,如下所示。

var text = 'return ((((((((((((((((((((((((((getHumanReadableLine("avHardwareDisable") + getHumanReadableLine("hasAccessibility")) + getHumanReadableLine("hasAudio")) + getHumanReadableLine("hasAudioEncoder")) + getHumanReadableLine("hasEmbeddedVideo")) + getHumanReadableLine("hasIME")) + getHumanReadableLine("hasMP3")) + getHumanReadableLine("hasPrinting")) + getHumanReadableLine("hasScreenBroadcast")) + getHumanReadableLine("hasScreenPlayback")) + getHumanReadableLine("hasStreamingAudio")) + getHumanReadableLine("hasStreamingVideo")) + getHumanReadableLine("hasTLS")) + getHumanReadableLine("hasVideoEncoder")) + getHumanReadableLine("isDebugger")) + getHumanReadableLine("language")) + getHumanReadableLine("localFileReadDisable")) + getHumanReadableLine("manufacturer")) + getHumanReadableLine("os")) + getHumanReadableLine("pixelAspectRatio")) + getHumanReadableLine("playerType")) + getHumanReadableLine("screenColor")) + getHumanReadableLine("screenDPI")) + getHumanReadableLine("screenResolutionX")) + getHumanReadableLine("screenResolutionY")) + getHumanReadableLine("version")));', 
 
     r = /\(((getHumanReadableLine\("\w+"\)[\s\+]*)+)\)/g, 
 
    temp = ""; 
 
while (text != temp) { 
 
    temp = text; 
 
    text = text.replace(r,"$1"); 
 
} 
 
document.write('<pre>' + text + '</pre>');

從這點上來說,它不應該是一個大問題,以減少文本轉換成所需的輸出格式。

+0

我只是喜歡https://regex101.com/r/wC5eK7/1來處理,理解和改進正則表達式。 Actionscript RegExpr與JavaScript提供的有些相似。 – karfau