1

我正在使用Visual Studio,並且想要刪除代碼上所有窗體中的圖標。的圖標被嵌入在RESX文件,所以就用下面的正則表達式以查找圖標,然後我使用的查找和替換:查找並替換以刪除我所有表單中的圖標

\<data name=\"\$this\.Icon\".+\n(.*\n)*^.+rEE=\n(.*\n)(.*\n) 

圖標存在於用下面的代碼的RESX文件:

 <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> 
     <value> 
      AAABAAgAICAQAAEABADoAgAAhgAAABAQEAABAAQAKAEAAG4DAAAwMAAAAQAIAKgOAACWBAAAICAAAAEA 
      ... 
      rEGAAaxBgAGsQYABrEHAAaxBwAOsQeAHrEHgH6xB+D+sQf//rEE= 
     </value> 
     </data> 

它的工作原理,但性能是非常糟糕的。我怎樣才能找到更快的正則表達式?

回答

2

說明

這個表達式:其中有name=$this.icon

  • 屬性

    • 查找數據標籤避免一些使用正則表達式的棘手的問題讀取非正規的標記語言

    <data\b(?=\s)(?=(?:[^>=]|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*?\sname="\$this\.Icon")(?:[^>=]|='[^']*'|="[^"]*"|=[^'"\s]*)*"\s?\/?>(?:(?!<\/data>)[\s\S])*?<\/data>

    enter image description here

    活生生的例子:http://www.rubular.com/r/FqdOI8H27X

    示例文字

    注意的第一個數據標籤有一些困難的邊緣情況

    <data onmouseover=' name="$this.Icon" ; funReplace("</data>", name) ; ' type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> 
         <value> 
          AAABAAgAICAQAAEABADoAgAAhgAAABAQEAABAAQAKAEAAG4DAAAwMAAAAQAIAKgOAACWBAAAICAAAAEA 
          ... 
          rEGAAaxBgAGsQYABrEHAAaxBwAOsQeAHrEHgH6xB+D+sQf//rEE= 
         </value> 
         </data> 
    <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> 
         <value> 
          AAABAAgAICAQAAEABADoAgAAhgAAABAQEAABAAQAKAEAAG4DAAAwMAAAAQAIAKgOAACWBAAAICAAAAEA 
          ... 
          rEGAAaxBgAGsQYABrEHAAaxBwAOsQeAHrEHgH6xB+D+sQf//rEE= 
         </value> 
         </data> 
    

    匹配

    [0] => <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> 
        <value> 
         AAABAAgAICAQAAEABADoAgAAhgAAABAQEAABAAQAKAEAAG4DAAAwMAAAAQAIAKgOAACWBAAAICAAAAEA 
         ... 
         rEGAAaxBgAGsQYABrEHAAaxBwAOsQeAHrEHgH6xB+D+sQf//rEE= 
        </value> 
        </data> 
    
  • 相關問題