2012-08-08 35 views
0

我有一個xml文件,需要在某些字段上有60個字符的限制。搜索/替換記事本++字符數限制

<Description>This is a long description that is really over 60 characters long and needs to be shortened</Description> 

我需要修剪每個出現所以它只有60個字符,因此輸出對上述那樣。

<Description>This is a long description that is really over 60 characters</Description> 

使用notepad ++如何使用Regex進行搜索和替換?

我有多個文件,我需要運行這個對每個文件大約有2000行,並有大約10-15次出現這個領域。

並非所有的字段都有超過60個字符,其中只有一些字符。數據

 <Product> 
     <SuppliersProductCode>PF01215</SuppliersProductCode> 
     <BuyersProductCode></BuyersProductCode> 
     <GTIN>0</GTIN> 
     <Description>This is a long description that is really over 60 characters long and needs to be shortened</Description> 
     <Properties> 
      <Quantity UOMCode="EA"> 
       <Packsize>1</Packsize> 
       <Amount>1</Amount> 
      </Quantity> 
     </Properties> 
    </Product> 

感謝

+0

很新的使用正則表達式,所以沒有嘗試很多設法找到()(。*)()位的權利,但無法找出替代。 – Mark 2012-08-08 14:58:26

回答

1

實例塊我覺得正則表達式,<Description>([^<]{0,60})[^<]*</Description>,匹配你想承擔什麼的描述並不會包含「<」。請注意換行符也被計算在內。如果您想避免這種情況,請使用<Description>\R?([^<]{0,60})[^<]*</Description>

在「替換」框中輸入<Description>\1</Description>\1引用由第一對括號之間的表達式匹配的內容。它被稱爲反向引用。 More info

+0

編輯原來的問題要更清楚一點,這將刪除標記,但我需要保留它們,但只需編輯它們之間的文本,只有60個字符。謝謝 – Mark 2012-08-09 07:22:55

+0

我希望這是更好的。讓我知道。 – Vortexfive 2012-08-09 07:43:31

+0

找不到任何匹配不是每個描述都長於60個字符,只是其中的一些。 – Mark 2012-08-09 11:36:56