Regex help: manipulate camel case

How can camel case words be renamed into ones with a blank?

ThisIsAnExample -> This Is An Example

So the state of the capitalized word beginnings should be maintained.

Turn on Case Sensitive and use a regexp from b([A-Z].*)#[/b] to \1 \2

Cool, thanks. Only one thing doesn´t work, that´s when a single uppercase character is included:
ANewFile -> ANew File.

Ugh, this would be so much easier of one could just write:

s/([A-Z])/\1 /g

[quote="MrC"]Ugh, this would be so much easier of one could just write:

s/([A-Z])/\1 /g[/quote]

You can call Perl via rename scripts if you want to. :slight_smile:

Not sure what is gained in this case, either. The # on the end of my expression is equivalent to the /g on the end of your Perl/SED-style thing.

Wouldn't that add a space after every single capital letter, too?

[quote="abr"]Cool, thanks. Only one thing doesn´t work, that´s when a single uppercase character is included:
ANewFile -> ANew File.[/quote]

If you just want a space inserted before each capital letter (ignoring the first one):

(.[^ ])([A-Z].)#
\1 \2

That'll mess up the file extension if it has capitals, of course. (Not that the first one wouldn't also potentially mess up the file extension.)

Not sure exactly what you're using this for so I don't know if that matters.

[quote="leo"][quote="MrC"]Ugh, this would be so much easier of one could just write:

s/([A-Z])/\1 /g[/quote]

You can call Perl via rename scripts if you want to. :slight_smile:
[/quote]
Understood, but built in would be so much quicker and easier. :slight_smile:

[quote="leo"]
Not sure what is gained in this case, either. The # on the end of my expression is equivalent to the /g on the end of your Perl/SED-style thing.[/quote]
But it doesn't work in the case mentioned above.

[quote="leo"]
Wouldn't that add a space after every single capital letter, too?[/quote]
Sure, but use negative lookbehind assertions to stop this (I didn't want to confuse the main point):

's/(?<!^)([A-Z])/ \1/g'

Is that down to the single character, or because the first and second letters are involved?

Perhaps it is because it gags on strings of caps. But that is probably for the better. These are often names, like OECD.

Nice to have this one. Goes alongside a growing stack I use to mend the silly names that people give to PDF files.

Yep, that works now. I have digitized my vinyl collection & have lots of those raw files in camel case (not sure why i´ve saved it like that a while ago),
but now i want to have the folder titles in the right way. :thumbsup:

Only because it's what you're used to. Anyway, we're not going to port/write our own implementation of Perl and bundle it with Opus. People who want Perl can install Perl, and Opus will call whatever Perl functions you want via the rename scripting feature. I don't see what the problem is. :slight_smile:

The only reason it didn't work is because I didn't realise it was meant to handle that case, not because of some deficiency in the way Opus handles regular expressions. It was simple to fix the regexp once that was pointed out.

Your regexp didn't work either. :slight_smile:

[quote="MrC"]Sure, but use negative lookbehind assertions to stop this (I didn't want to confuse the main point):

's/(?<!^)([A-Z])/ \1/g'[/quote]

That's quicker and easier now? :slight_smile:

Can someone please help me to adjust the above samples so they work with file names that have a prefix before the CamelCase starts?

For example, in this case I just want to fix the CamelCase after the _

PC309_Underbridge.mp3
PC310_WhenTheLadySpeaks.mp3
PC311_LaMadreDelOro.mp3
PC312_Enginesong.mp3
PC313_ThisIsAGhostStory.mp3
PC314_TheNamelessSaint.mp3
PC315_Stranger.mp3
PC316_TheMeaningOfLove.mp3
PC317_BeeYard.mp3
PC318_TheMSGGolem.mp3
PC319_AmericaThief.mp3
PC320_BabaMakosh.mp3