0

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.

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.
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Ken
  • 1,001
  • 3
  • 14
  • 27

2 Answers2

3

Try this regex.

(?<=\d)-(?=\d)
edi_allen
  • 1,878
  • 1
  • 11
  • 8
  • Genius! Thank you, works perfectly. For other users, this is the FIND expression you want, then the REPLACE text would just be blank (removes dashes). Thank you edi_allen – Ken Oct 31 '13 at 19:15
2

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. 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.

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).

$0 contains the whole match. $1 contains the first captured group and $2 contains the second captured group.

Community
  • 1
  • 1
Jerry
  • 70,495
  • 13
  • 100
  • 144