Skip to main content

Regular expressions bulk rename tool for multiple files

Project description


Regular expressions bulk rename tool for multiple files

GitHub version PyPI version Build Status codecov


enter regex-rename for help:

$ regex-rename 
regex-rename v0.1.1 (nuclear v1.1.5) - Regular expressions bulk rename tool for multiple files


   PATTERN       - Regex pattern to match filenames
   [REPLACEMENT] - Replacement regex pattern for renamed files. Use \1, \2 syntax to make use of matched groups

  --version                   - Print version information and exit
  -h, --help [SUBCOMMANDS...] - Display this help and exit
  -r, --rename                - Does actual renaming files instead of just testing replacement pattern
  --full                      - Enforces matching full filename against pattern
  --pad-to PAD_TO             - Applies padding with zeros with given length on matched numerical groups


pip3 install regex-rename


  • Python 3.6 (or newer) with pip


Imagine you've got audio files awfully named like this:

  • Stanis▯aw+Lem+Invincible+(1).mp3
  • Stanis▯aw+Lem+Invincible+(2 ).mp3
  • Stanisław_Lem_Invincible (3) .mp3
  • ...
  • Stanis▯aw+Lem+Invincible+(51).mp3

and you want to rename all of them in a manner 01 The Invincible.mp3 (extracting number from the end and put it at the beginning and padding it to 2 digits by the way).

Step 1: Testing matching pattern

Our Regex pattern to match those files and extract number from parentheses should be like this: .+\((\d+) ?\).+

Let's test matching pattern: regex-rename '.+\((\d+) ?\).+'
Usage example
Notice that regex groups are extracted in logs.

Step 2: Testing replacement pattern

We'd like to replace all files to a pattern: \1 The Invincible.mp3 (\1 is a first extracted group from matching pattern). Regex can't easily pad numbers with zeros. Fortunately, we can use --pad-to=2 to obtain 2-digit numbers

Let's test it: regex-rename '.+\((\d+) ?\).+' '\1 The Invincible.mp3' --pad-to=2
Usage example

Step 3: Actual renaming

All above commands were just testing our patterns so that we could experiment with regex patterns. Only when we're sure that everything is matched correctly, we can use --rename flag which does the actual renaming:
regex-rename '.+\((\d+) ?\).+' '\1 The Invincible.mp3' --pad-to=2 --rename
Usage example

From now files are named properly:

  • 01 The Invincible.mp3
  • 02 The Invincible.mp3
  • 03 The Invincible.mp3
  • ...
  • 51 The Invincible.mp3

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

regex-rename-0.1.1.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

regex_rename-0.1.1-py3-none-any.whl (6.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page