簡體   English   中英

Notepad ++:搜索並替換為正則表達式

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM