2014-11-05 140 views
0

後,我需要更換,但不變的字符之間留:替換之前和文本

例子:

<column name="propertys_uid">30</column> 
<column name="property_name">Villa</column> 
<column name="property_street">5th street</column> 
<column name="property_town">New York</column> 

應該成爲

<yourreference>30</yourreference> 
<name>Villa</name> 
<street>5th street</street> 
<town>New York</town> 

正如你所看到的內容> ... <不應該被改變。正常的查找和替換將不起作用,因爲總是需要不同。我覺得我得到的第一個步驟找到使用<column name="propertys_uid">.*?</column>但它不是在與<yourreference>*?</yourreference> –

任何建議替換工作將不勝感激

回答

0

您可以使用捕獲組,請更換。所以,舉例來說:

查找:<column name="propertys_uid">([^<]+)</column>

替換:<yourreference>$1</yourreference>

這將使<yourreference>30</yourreference>在你的榜樣


如果原始標籤的名字起成所需更換,你也可以這樣做:

查找:<column name="property_([^"]+)">([^<]+)</column>

替換:<$1>$2</$1>

這將使<name>Villa</name>在你的榜樣

0

你可以錄製宏並辦理一步每一步替換。

開始錄製宏,則:

  • CTRL H
  • 選擇了Search Mode

重複下面的步驟爲每個元素

  • 添加 '正則表達式'你的正則表達式在Find What領域,如<column name="propertys_uid">(.*?)</column>
  • Replace With場添加置換<yourreference>$1</yourreference>
  • 單擊全部替換按鈕

你做了之後,每個元素停止錄製宏並保存它。

要在Windows 7/8上查找宏,請轉至C:\Users\{{USERNAME}}\AppData\Roaming\Notepad++\shortcuts.xml。您必須關閉記事本++以將宏保存到xml文件。

這樣做有點複雜,但這樣做會工作並節省腦力! phew

0

我在那裏看到notepad ++標記,你可以在notepad ++中使用group regex。

只是修改你的正則表達式有點像這樣<column name="propertys_uid">(.*)<\/column>並取代<yourreference>\1</yourreference>確保您的搜索模式是在「正則表達式」。您可以從<column name="propertys_uid">30</column>