繁体   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