2017-01-23 243 views
1

我正在使用notepad ++並試圖在特定標記中查找/替換XML文件中特定單詞的出現。正則表達式從字符串中提取子字符串

例如: XML文件包含

<alerts> 
    <ccEmails>[email protected],[email protected]</ccEmails> 
    <toEmails>[email protected]</toEmails>    
</alerts> 

我需要myexample中目前更換內部<ccEmails><toEmails>

我在https://regex101.com/r/Q8UB6a/1試圖ccEmails.*(example).*ccEmails例如,它僅返回最後一次出現。另外,我無法用另一個替換字符串。

當我試圖在這個記事本+ +,我正在裏面<ccEmails>

enter image description here

所有字符串中,你能幫我在查找/替換包含特定標籤內子。請讓我知道是否需要更多細節。

回答

1

如果你打算使用查找和替換對話框,你需要使用一個基於\G正則表達式像

(?:<ccEmails>|\G(?!^))[^<]*?\K\bexample\b 

myexample取代。看到online regex demo.

詳細

  • (?:<ccEmails>|\G(?!^)) - 無論是<ccEmails>或最後一次成功的比賽
  • [^<]*?結束 - 任何0+字符超過<儘可能少
  • \K其他 - 省略目前匹配的文字 - \bexample\b - 整詞example

enter image description here

0

(<ccEmails>[^<>][email protected])example\.替換爲\1myexample.,並進行全部替換。替換全部將需要進行兩次或更多次,因爲每次只更改所需字符串中的一個example

相關問題