简体   繁体   English

Notepad ++:搜索并替换为正则表达式

[英]Notepad++: Search and Replace with Regular Expression

I have thousands of entries in Notepad++ (amongst other text mixed in), where I'm trying to remove the dash symbol in-between any 2 numbers. 我在Notepad ++中有成千上万的条目(以及其他混入的文本),我试图在其中删除任意两个数字之间的破折号。

I have data like this: 我有这样的数据:

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

Desired Results: 所需结果:

text text this is text here
2345678
this is more text here 
1234585 this is more text here
or text is here too 5835974

I've tried: 我试过了:

Find: [0-9]-[0-9] (which works to find the (#)(dash)(#)
Replace: $0, $1, \1, ^$0, "$0", etc.

试试这个正则表达式。

(?<=\d)-(?=\d)

What's wrong with your method of: 您的方法有什么问题:

Find: [0-9]-[0-9] (which works to find the (#)(dash)(#)
Replace: $0, $1, \1, ^$0, "$0", etc.

Is that $0 or $1 etc refer to captured groups while your find regex doesn't have any. $0$1等指向捕获的组,而您的查找正则表达式没有任何东西。 It would have worked if you did: 如果您这样做,它会起作用:

Find: ([0-9])-([0-9])
Replace: $1$2

$1 would contain the first digit and $2 the second. $1将包含第一个数字, $2将包含第二个数字。

Of course now, using lookarounds like in edi_allen's answer ( (?<= ... ) is a positive lookbehind and (?= ... ) is a positive lookahead) also work and avoids you the trouble of using backreferences (the $1 and $2 ). 当然,现在,在使用lookarounds像edi_allen的回答(?<= ... )是一个积极的回顾后和(?= ... )是一个积极的前瞻)也工作,避免您在使用反向引用(的麻烦$1$2 )。

$0 contains the whole match. $0包含整个比赛。 $1 contains the first captured group and $2 contains the second captured group. $1包含第一个捕获的组, $2包含第二个捕获的组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM