Multi Rename: Add space before CamelCase upper case letters

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
Zefrem23
Junior Member
Junior Member
Posts: 7
Joined: 2013-05-12, 09:02 UTC

Multi Rename: Add space before CamelCase upper case letters

Post by *Zefrem23 »

Changing ThisTypeOfFileName.ext to This Type Of FileName.ext

Hi folks, Can anyone perhaps help me with a Total Commander-compatible regular expression I can use in the multi-rename tool to change CamelCase filenames into Separate Word Filenames?

I've tried ([a-z])(A_Z) replacing with $1 $2 but it produces a very weird result, sticking spaces in all over the place. My regex-fu isn't very good and I hope someone else with a bit more savvy can give me a boost :)

Thanks everyone!
umbra
Power Member
Power Member
Posts: 876
Joined: 2012-01-14, 20:41 UTC

Post by *umbra »

Search for:

Code: Select all

(?-i)([a-z])([A-Z])
Replace with:

Code: Select all

$1 $2
Don't forget to enable regex :)

For more info open Multi Rename Tool and press F1. There is also a link to supported regular expressions somewhere in the text.
Windows 10 Pro x64, Windows 11 Pro x64
Zefrem23
Junior Member
Junior Member
Posts: 7
Joined: 2013-05-12, 09:02 UTC

Post by *Zefrem23 »

Thank you very much, so close yet so far ;)
User avatar
white
Power Member
Power Member
Posts: 6016
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Post by *white »

2Zefrem23
You can also use the checkbox "^" instead of the code "(?-i)".
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Post by *milo1012 »

This isn't a trivial task since you have to consider many "special" cases or restrict yourself to certain rules.
(what happens when there are two or more upper case letters following in a row,
do you also want to consider non-latin letters, what if whitespace is enclosed ...)

Well, try this:

If names always start with capital letter:
Search for:
(?-i)([A-Z]{1})([^A-Z]*)
Replace with:
$1$2_
(Replace _ with a space after $2 !)


If names start with non-capital-letter sign (anything except capital letter):
Search for:
(?-i)([^A-Z]*)([A-Z]{1})
Replace with:
$1 $2
(space between $1 and $2 !)

This should work for most cases except whitespace.
You'll get double whitespace in that case, but you should be able to delete the second one in another session quite easy.

AFAIK there's no way to handle both cases at once, i.e. name can start with capital letter and anything else without adding additional spaces.
If someone knows, feel free to add.
Post Reply