Sunday, July 22, 2007

TextPad Regular Expressions: Replace Leading Whitespace with ' '

TextPad is my text-editor of choice. It's simple, fast and lightweight. Plus it supports regular expressions and wildcard searches.

When preparing a post for upload onto the site I often need to replace the leading whitespace with HTML encoded whitespace. This replacement will have to be run for leading whitespace character you wish to replace, but don't worry TextPad will let you know when there are no more replacements to be made.

Inside the TextPad Replace dialog ... (Don't copy the quote marks!)

Find what:  "^\(\(&nbsp\;\)*\)[[:space:]]"

Replace with:  "\1\ "

To restore the whitespaces use the follow expression.

Find what:  "^\(\([[:space:]]\)*\)&nbsp\;"

Replace with:  "\1 " <-- Notice that there is a single space character after the \1.

Submit this story to DotNetKicks

0comments: