Regular expressions in Notepad++

There are many useful articles about Regular expressions in Notepad++ in the Internet. I have decided to keep my own as a kind of my personal cheat-sheet.

Removing attachments in Thunderbird files

Find: (Content-Transfer-Encoding: base64)(.*?)(\r\n--)
Replace: \1\3
. matches newlines

Convert list of named values into table

This regular expression extracts values from a list of named values and puts them in table columns. New table row starts with Delimiter:

NameOfValue1: NumberValue1
NameOfValue2: TextValue2
SomeUselessMultilineText1
NameOfValue3 = URLvalue3
SomeUselessMultilineText2
Delimiter ********
NameOfValue1: NumberValue4
NameOfValue2: TextValue5
SomeUselessMultilineText3
NameOfValue3 = URLvalue6
SomeUselessMultilineText4
Delimiter ********

The resulting table looks like this:
NumberValue1 \t TextValue2 \t URLvalue3
NumberValue4 \t TextValue5 \t URLvalue6

(NameOfValue1: )(\d+)(.*?)(NameOfValue2: )([[:alnum:][:punct:]]+)(.*?)(NameOfValue3 = )([[:alnum:][:punct:]]+)(.*?)(Delimiter\s\*{8})
\2\t\5\t\8
. matches new line

2 Comments

  1. Alex

    Specified regular expression depends on the environment where it supposed to be use and additional commands such as : “:alnum:”, “:punct:” need to be modified or replaced. There is simpler way to do it:
    (NameOfValue1:\s+.*)\n+(NameOfValue2:\s+.*)\n+.*\n+(NameOfValue3\s=\s.*)[\n\w\s]+\*+

    • drewbul

      Thank you for the reply, Alex.
      When I make the replacement in Notepad++ using your regular expression (and \2\t\5\t\8 as the replacement value), I get this result:

      NameOfValue2: TextValue3
      Some Useless

      … which is different from the desired. So it does depend on the environment. For me Notepad++ is the most convenient place to make such replacements.

Leave a Reply

Your email address will not be published. Required fields are marked *