3
votes

I'd like to use Notepad++ to replace all leading spaces on a line with a like number of given characters. So for instance, I want to change:

zero
 one
  two
   three

into:

zero
@one
@@two
@@@three

I haven't been successful at getting this working. I did find Regex to replace html whitespace and leading whitespace in notepad++, but wasn't able to get the result I wanted.

Is this possible with Notepad++? I'd rather not have to write code to do this...

2

2 Answers

7
votes

As Tim's answer indicates, this can't be done in a single search/replace, however here is how you can accomplish the same task fairly quickly using multiple replacements:

Find: ^( *)[ ]

Replace with: \1@

Now just spam the "Replace All" button until it indicates that there were no matches to replace. This will replace a single space at the beginning of each line on each click, so it will require the same number of clicks as your most-indented line.

Make sure "Regular expression" is selected as the search mode.

1
votes

You would need variable-length lookbehind assertions to do this in a single regex, and Notepad++ doesn't support these.

For the record, in EditPadPro you can search for (?<=^ *)\s and replace with @.