2013-07-10 31 views
-1

我想找到4000所有的數字4999,並與7用另一個發現使用替換文本一個

例如更換領先4:

4000 -> 7000 
4015 -> 7015 
4987 -> 7987 

我試着用7\1更換4\d\d\d\d ,但它沒有奏效。

+2

[這已在meta上討論過](http://meta.stackexchange.com/questions/188408/give-me-teh-regez-questions) – user000001

回答

1

嘗試低於notepad++

搜索4(\d\d\d)7\1取代。

3

搜索(?<!\d)4(\d{3})(?!\d)7\1取代。

說明

(?<!\d)  # Negative lookbehind: check if there is no digit preceding 4 
4   # match 4 
(   # start group 1 
    \d{3} # match 3 digits 
)   # end group 1 
(?!\d)  # Negative lookahead: check if there is no digit following the 3 digits 

更換:\1指組1

enter image description here

雖然 Tim的解決方案是更好:P

+1

在記事本++中不起作用 – gruber

+1

@gruber我使用NP ++並測試過出來,一定要檢查在「搜索模式」 – HamZa

+1

「正則表達式」這也將改變40000 70000 ...... –

3

搜索\b4(\d{3})\b並用7\1替換,使用正則表達式替換模式。

word boundaries確保您不會意外地匹配1400040000

相關問題