Remove spaces at beginning of line if first non-space character is a letter (Notepad++)

notepadregex

I am using Notepad++ to cleanup some wiki code and would like to do the following: I need to remove all leading spaces from a line but only if the first non-space character is a letter. Here's an example:
Input:

    This should be changed
    * This should not be changed
    //This souldn't be changed either

Output:

This should be changed
    * This should not be changed
    //This souldn't be changed either

Thanks!

Best Answer

You can use the RegEx find and replace option.

Search for

 ^\s*(\w.*)$

Replace with

\1

enter image description here

Explanation:

The search is:

^ - Beginning of the line

\s - A whitespace character

* - 0 or more of them

( - Begin a capture group

\w - A word character ([a-z] or [A-Z])

. - Any character

* - 0 or more of them

) - End our capture group

$ - End of the line

Replace with:

\1 - The contents of the first capture group (Our word character and all characters after that)