A practical example of regex.

I want to transform a collections of files from this:

Into this:

I could rename each file by hand, but this would take a bit of effort, is boring and annoying. Using a regex expression and PowerRenamer I can do this in one go.

This is the regular expression I used to match the components of the file names:


And here is the regular expression I used to transform the file names:

$2.$3.$4 - INVOICE - Company - $1_1

Regex is a bit cryptic, but lets break the key concepts down.

First, we need to match the 16 digit account number:


The square brackets matches a single digit zero through 9. The curly braces tells regex to do this match sixteen times. The rest of the expression refines this a bit.

The ^ indicates to start from the beginning of the line. The parentheses puts this into a group so it can be references later by a dollar sign and a number.

The second significant part of the expression:


Matches the month, day and year of the file name and puts them into groups so we can easily transform them putting them into a form yyyy.mm.dd.