Sublime Text 2 : Python – Search And Replace Tips(Regual Expression)

Here is some tips and tricks that I used to clean my python scripts before putting it for code review. These are some very basic of search and replace that you can do in Sublime Text 2. Improve these as you needed and you can speed up your work by some margin.

  1. Add Space between comma(,) and a letter
    Find What : “,((?! ).)”
    Replace With : “, $1”
  2. Adding Space before and after operators(+, *, -, /, =)
    Find What : “((?! ).)(+|*|-|/|=|%)((?! ).)”
    Replace With : “$1 $2 $3”
  3. Remove space after “(“
    Find What : “(()( )”
    Replace With : “$1”
  4. Remove space before “)”
    Find What : “( )())”
    Replace With : “$2”
  5. Remove space at the end of line
    Find What : “(.)( )(n)”
    Replace With : “$1$3”