Regular Expressions

This is a collection of regular expressions that I created for some particular tasks. I show them here for self-reference and in case you have a similar task at hand.

Check out vim-regex-collection where I turned the regular expressions for Vim into a plugin.

Email Rename Regex

When you export emails from Thunderbird, it generates .eml files which have a pretty unusable name for me:

Re: Happy Birthday - Full Name <email@example.com> - YYYY-MM-DD HHMM.eml

The problem with those names are that a lot of those files in a folder are going to be sorted by subject, which does not even work with the Re: in front of some emails.

I renamed all those emails to a more sensible format:

YYYYMMDD-HHMM-Full Name <email@example.com>-Re: Happy Birthday.eml

This rename command does the trick:

rename 's#(.*?)([^/]*) - ([^/]*) - (\d{4})-(\d{2})-(\d{2}) (\d{4})\.eml#$1$4$5$6-$7-$3-$2.eml#'

LaTeX Inner Product

The mathematicians’s notation for the inner product looks like this for two vectors \(\vec a\) and \(\vec b\):

\[\left\langle \vec a, \vec b \right\rangle\]

The LaTeX code for this is:

\[ \left\langle \vec a, \vec b \right\rangle \]

I then defined myself a new command that does this easier, like so:

% Definition
\newcommand{\inner}[2]{\left\langle #1, #2 \right\rangle}

% Usage
\[ \inner{\vec a}{\vec b} \]

So then I had to replace the \left\langle and so with the new notation. This Vim command did the trick:

:%s/\v\\left\s*\\langle\s*([^,]{-})\s*,\s*([^,]{-})\s*\\right\s*\\rangle/\\inner{\1}{\2}/gc