Cenderze
Cenderze

Reputation: 1222

Replace a number followed by a tab with keeping the number and adding a second tab using REGEX in Notepad++

I have a file with this appearence:

399 MISC    KAK/BAR  0     0    0   0   0   0           
2   FOO     BAR      FOO   0    0   0   0   0   0

where each space is a tab in practice

I want to remove all tabs in the string, so I can later import the file into Excel using a tab delimiter.

For this my thought is to replace each number ending with a tab with keeping the number, but adding an additional tab. Then I want to

replace \t with (i.e one blank step)

For the first step, to add an additional tab behind each number ending a sequence I've tried to use the following Replace using REGEX:

Search for ^[\0-9]\t
Replace with $0\t

This however only works when I have a single number, and only if it occurs in the first column. In my example it becomes:

399\tMISC\tKAK/BAR\t0\t0\t0\t0\t0\t0            
2\t\tFOO\tBAR\t0\t0\t0\t0\t0

but I want it to become:

399\t\tMISC\tKAK/BAR\t0\t\t0\t\t0\t\t0\t\t0\t\t0            
2\t\tFOO\tBAR\t0\t\t0\t\t0\t\t0\t\t0

i.e. a double tab after each number sequence. In my later output I included the tabs as \t as I Believe it was rather hard to determine whether it was a double or single tab when I wrote the actual output.

Does anyonw know how I can achieve this?

Upvotes: 1

Views: 1468

Answers (2)

Jonas Byström
Jonas Byström

Reputation: 26179

Search:  \d+\t
Replace: $0\t

The expression \d+ matches any (uninterrupted) string of digits, such as 01446. Notepad++ 6.0 or newer ships with built-in PCRE support.

Upvotes: 0

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627219

Use the following regex replacement:

Find What:     [0-9]\t
Replace With: $0\t

The ^ caret is a start of line anchor in NPP, and it will only let you pattern match if there is one digit at the start of a line that has a tab after it. So, [0-9]\t will match any 1 digit and a \t after it anywhere on a line.

Details:

  • [0-9] - matches any ASCII digit
  • \t - a tab
  • $0 - a backreference referencing to the whole matched text

Upvotes: 1

Related Questions