Notepad ++: search and replace with regex

I have thousands of entries in Notepad ++ (among other mixed texts) where I am trying to remove the dash character between any two 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 tried:

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

      

0


source to share


2 answers


Try this regex.



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

      

+3


source


What's wrong with your method:

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

      

This is what $0

or $1

etc. refer to captured groups, while your regex has no lookup. It would work if you did:

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

      



$1

will contain the first digit and the $2

second.

Of course, now, using images such as edi_allen? Answer ( (?<= ... )

is positive lookbehind and (?= ... )

a positive outlook), also works and avoids the problem of using backlinks ( $1

and $2

).

$0

contains the entire match. $1

contains the first captured group and $2

contains the second captured group.

+2


source







All Articles