Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let's say I have a text file with two columns of numbers separated by a single tab:

23  45
456 872
1569    489
78  357
789 94

and I want to be able to add an additional tab between the columns. For the example to make better sense, let's say these columns are surrounded by large amounts of text.

My search expression would be something like this: [0-9]\t[0-9]

How would I format my replace expression so that I don't lose:

3 6 9 8 9 in the first column

4 8 4 3 9 in the second column

Or, more generally, how do I avoid altering part of my search expression, which is needed to identify the correct area of the text?

If I use [0-9]\t\t[0-9] as my replace expression, I get this:

2[0-9]      [0-9]5
45[0-9]     [0-9]72
156[0-9]        [0-9]89
7[0-9]      [0-9]57
78[0-9]     [0-9]4

(Obviously, I have my search mode set to "Regular expression".)

Any help greatly appreciated!

share|improve this question

1 Answer 1

up vote 8 down vote accepted

Notepad++ allows you to use capture groups in the search regex, and then refer to those in the replacement.

so, use the search term ([0-9])\t([0-9]). The parentheses tell Notepad++ to "capture" the part of the text that matches that part of the regex - in this case, the numbers before and after the tab.

In your replacement expression, refer to those capture groups, like this: \1\t\t\2. The \1 and \2 refer to the first and second capture groups.

share|improve this answer
    
Awesome, thanks! –  user42669 Jul 12 '10 at 20:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.