[英]Notepad++: Search and Replace with Regular Expression
我在Notepad ++中有成千上萬的條目(以及其他混入的文本),我試圖在其中刪除任意兩個數字之間的破折號。
我有這樣的數據:
text text this is text here
234-5678
this is more text here
123-4585 this is more text here
or text is here too 583-5974
所需結果:
text text this is text here
2345678
this is more text here
1234585 this is more text here
or text is here too 5835974
我試過了:
Find: [0-9]-[0-9] (which works to find the (#)(dash)(#)
Replace: $0, $1, \1, ^$0, "$0", etc.
試試這個正則表達式。
(?<=\d)-(?=\d)
您的方法有什么問題:
Find: [0-9]-[0-9] (which works to find the (#)(dash)(#)
Replace: $0, $1, \1, ^$0, "$0", etc.
是$0
或$1
等指向捕獲的組,而您的查找正則表達式沒有任何東西。 如果您這樣做,它會起作用:
Find: ([0-9])-([0-9])
Replace: $1$2
$1
將包含第一個數字, $2
將包含第二個數字。
當然,現在,在使用lookarounds像edi_allen的回答 ( (?<= ... )
是一個積極的回顧后和(?= ... )
是一個積極的前瞻)也工作,避免您在使用反向引用(的麻煩$1
和$2
)。
$0
包含整個比賽。 $1
包含第一個捕獲的組, $2
包含第二個捕獲的組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.