Salesforce, Python, SQL, & other ways to put your data where you need it

Need event music? 🎸

Live and recorded jazz, pop, and meditative music for your virtual conference / Zoom wedding / yoga class / private party with quality sound and a smooth technical experience

Re-indenting with Notepad++ regex replace

08 Oct 2020 🔖 tips
💬 EN

The other day I came up with a ridiculously inefficient regex replace for Notepad++ to re-indent some code from 3 spaces per indent (my team’s standard for a certain codebase – no idea how they settled on 3) to 1 (for tight display on this blog).

  • Search -> Replace (ctrl+H)
  • Search Mode: Regular expression
  • Start with Find what of:
^   ([^ ])
  • Start with Replace with of:
  • Repeat, adding 3 spaces at a time after the ^ to Find what and 1 space at a time to the beginning of Replace with, until the following replace (and the one before it), at 6 & 7 levels deep of indenting, both had 0 results

  • Stopped at Find what of:

^                     ([^ ])
  • Stopped at Replace with of:

I’m sure I could have done better, but it got the job done.

What do you do to quickly change the indentation of code?

--- ---