ONLY MY KIT

FILE GUIDE / BATCH RENAME · REGEX

Rename hundreds of files at once: practical regex examples for beginners

Renaming a few documents manually is fine. Repeating the same edit across 50, 100 or 500 files is a job for a rule. You do not need to study regex first: copy the closest Before → Pattern → Replace → After example and inspect the preview.
Published 2026-08-18Updated 2026-08-18About 12 min
01

Regex finds a structure, not one literal name

IMG_1234.jpg and IMG_5678.jpg contain different digits but share the structure “IMG_ followed by numbers.” A regular expression matches that structure.

Only My Kit applies JavaScript regex to the base name without its extension. The global flag means every match inside a name is replaced.

02

Start with prefixes, spaces and trailing numbers

These five common examples use an empty Replace value to delete a match when needed.

Remove IMG_ at the start

Before
IMG_001.jpg
IMG_002.jpg
IMG_003.jpg
Pattern
^IMG_
Replace
Empty string
After
001.jpg
002.jpg
003.jpg

^ anchors the match to the start of the base name.

Remove the Screenshot_ prefix

Before
Screenshot_2026-08-17.png
Screenshot_2026-08-18.png
Pattern
^Screenshot_
Replace
Empty string
After
2026-08-17.png
2026-08-18.png

Only names starting with this exact prefix change.

Replace spaces with underscores

Before
summer vacation 001.jpg
summer vacation 002.jpg
Pattern
\s+
Replace
_
After
summer_vacation_001.jpg
summer_vacation_002.jpg

\s+ matches one or more consecutive whitespace characters.

Remove a trailing (1) or (2)

Before
report (1).pdf
report (2).pdf
report (17).pdf
Pattern
\s*\(\d+\)$
Replace
Empty string
After
report.pdf
report.pdf
report.pdf

The optional space and parenthesized number are matched only at the end. Duplicate outputs are flagged.

Change the final number before the extension

Before
event_001.jpg
session_42.jpg
Pattern
\d+$
Replace
final
After
event_final.jpg
session_final.jpg

Regex runs on the base name, so $ refers to the point before .jpg.

03

Reformat dates and combine alternatives

Captured values can be reused and several prefixes can share one pattern. Test a small copied set first.

Reformat a date

Before
20260817_photo.jpg
20260818_photo.jpg
Pattern
^(\d{4})(\d{2})(\d{2})_
Replace
$1-$2-$3_
After
2026-08-17_photo.jpg
2026-08-18_photo.jpg

Captured year, month and day are reused with JavaScript replacement tokens $1, $2 and $3.

Normalize repeated whitespace

Before
product    image   01.jpg
Pattern
\s+
Replace
_
After
product_image_01.jpg

Any run of whitespace becomes one underscore.

Remove one of several prefixes

Before
KakaoTalk_trip.jpg
DSC_1042.jpg
Screenshot_home.png
IMG_7788.jpg
Pattern
^(KakaoTalk_|DSC_|Screenshot_|IMG_)
Replace
Empty string
After
trip.jpg
1042.jpg
home.png
7788.jpg

The | inside parentheses means one of these alternatives.

Find every number run

Before
photo_12_take_3.jpg
Pattern
\d+
Replace
N
After
photo_N_take_N.jpg

The tool uses the global flag, so every digit run in the base name changes.

Remove a trailing _copy

Before
proposal_copy.docx
photo_copy.jpg
Pattern
_copy$
Replace
Empty string
After
proposal.docx
photo.jpg

$ limits the match to the end instead of changing _copy in the middle.

04

Beginner regex cheat sheet

A dot means any character in regex; use \. for a literal period. .* is deliberately broad and should usually have a clear boundary around it.

ExpressionMeaning
^Start of the base name
$End of the base name
\dOne digit
\d+One or more digits
\sA whitespace character
\s+One or more whitespace characters
.Any single character
.*Any number of characters
()Group a matched part
$1Reuse the first group
\.A literal period
05

Extensions and capture groups in this tool

The tool splits a name at the final period and runs regex only on the base. In report (1).pdf, $ is therefore the position after (1), before .pdf.

JavaScript String.replace allows $1 and $2 to reuse captured groups. Patterns are created with the g flag, so all matches change.

The extension field only renames the extension text. Calling a JPG file .webp does not convert its image data.

06

Always inspect the preview before applying

One rule affects every selected file. Broad patterns such as \d+ or .* can catch product and version numbers as well as the date you intended.

An invalid pattern blocks the download. Duplicate output names also trigger a warning and disable ZIP creation.

  • Original files are not renamed in place; renamed copies go into a ZIP.
  • Test mixed file sets in smaller groups.
  • Make the pattern narrower if any preview row is unexpected.
  • Removing (1) and (2) from identical base names creates a collision.
07

Start from an example instead of memorizing syntax

File Renamer provides a regex toggle, quick help and a Before/After preview for every file. Copy the closest example and change only the literal prefix first.

The downloaded ZIP contains renamed copies while the source files remain untouched.

08

FAQ

Does regex include the extension?
No. The current tool separates the final extension and applies regex to the base name.
Does $1 replacement work?
Yes. The tool uses JavaScript replacement syntax, including $1, $2 and later capture groups.
Are original files renamed?
No. The browser previews names and packages copied file data under the new names in a ZIP.