Re: [問題] 請問例外的寫法

作者: rkcity (喵。罐頭)   2012-08-01 16:48:17
※ 引述《PurpleCrow (紫烏鴉)》之銘言:
: ※ 引述《xvid ()》之銘言:
: : 語言:C++ TR1 Regular Expressions
: : 環境:gdipp內的xml設定檔
: : http://code.google.com/p/gdipp/wiki/SETTING_Beta
: : 由於原本該程式設計的邏輯為exclusion list(不渲染的黑名單),
: : 我想利用RE寫出白名單的表示式,不過只找到'^'於[]有except的作用,
: : 但只能對[]內的字元作成例外條件。
: : 換句話說,有無寫法可以對字串作為例外條件,也就是某字串以外的輸入皆符合?
: : 這是一個網站提供的範例
: : ((?!(notepad|mspaint)\.exe).)*
: : 但執行結果不正確:(
: : 有請各位幫忙!謝謝!
: : 不好意思,似乎我表達的有些模糊,下面作點補充。
: : gdipp是個字體渲染的軟體,能以編輯xml內容作設定,其中部分內容如下:
: : <exclude>
: : <process>conhost\.exe</process>
: : <process>dwm\.exe</process>
: : <process>logonui\.exe</process>
: : <process>service\.exe</process>
: : <process>spoolsv\.exe</process>
: : <process>svchost\.exe</process>
: : <process>taskhost\.exe</process>
: : <process>userinit\.exe</process>
: : <process>werfault\.exe</process>
: : <process>wininit\.exe</process>
: : <process>winlogon\.exe</process>
: : </exclude>
: : 上述的描述是讓conhost.exe、dwm.exe等系統執行程序不使用gdipp的渲染。
: : 由於我只想對特定一兩個程式使用gdipp渲染字體,依照上述的寫法,我必須把所有可能的執行檔名稱加入上面的列表,將會十分不方便。
: : 所以想利用該程式支援的RE表達(例如:notepad.exe及mspaint.exe以外的所有*.exe)加入上述的exclude process
: conhost.exe
: dwm.exe
: logonui.exe
: service.exe
: spoolsv.exe
: svchost.exe
: taskhost.exe
: userinit.exe
: werfault.exe
: wininit.exe
: winlogon.exe
: notepad.exe
: mspaint.exe
: \w+(?<!notepad|mspaint)\.exe
: 會得到前11個
: 不知道是不是你說的意思
: 另
: 該軟體只能exclude不能include嗎?
: 可以的話就不用那麼麻煩了 ^ ^;
借題詢問一下各位前輩..
http://regexr.com?31mr3
- - - - - - - -
Context
- - - - - - - -
-size 512
-size 556
-size 512556
-size 556556
-size 768
-size 512768
-size 556768
- - - - - - - -
- - - - - - - -
RegExp
- - - - - - - -
-size (?!512|556)
- - - - - - - -
這樣子可以抓出 768 前的 -size
可是如果我想要抓的是 不是512和556
也就是會包含512556 556556 512768 556768等雖是512 556開頭
但整體數字不是512和556的話
應該要怎麼改呢?
另外,如果我想要順便抓出後面這個數值的話
(?!512|556)因為是不包含其結果 所以沒辦法用$1取得 >"<
感謝各位前輩 m(_ _)m

Links booklink

Contact Us: admin [ a t ] ucptt.com