Fine tuning some rename functions

I am using various rename and Regex commands to rename mainly MP3 files. For example, i replace all "The" with lowercase "the", using

@NoDeselect
rename PATTERN="The" TO="the" FINDREP

but how can i avoid having words like "There" or "Them" also being affected, ending up lower case? It seems like some Regex would do a better job here.

Another small question, how can i retain the upper case letter following scottish "Mc" name prefixes? The way the command works now, "McDonalds" would be "Mcdonalds" after a run.

If you're aiming to match a particular word without matching other words that contain it then you need to do something about the characters before and after the word.

Here's one way to do it, using your "The" example, with regular expressions:

Old name: b(^| )(The)($| |.)(.*)#[/b]
New name: \1\2the\4\5

(^| ) will match either the start of the string or a space.

($| |.) will match the end of the string, a space or a dot.

So the expression only matches "The" when it's surrounded by spaces, or at the start or end of the filename.

The # on the end of the old name tells Opus to repeat the regexp until the filename stops changing. Without that only one "The" would be changed.

To deal with more esoteric stuff, like upper-casing the first letter after "Mc", I think you'll need to delve into rename scripting. Steves titlecase script would make a good starting point as it already splits the filename up into words and then applies logic to each word separately.

Leo, thanks a lot, it works very well. I made a direct command button instead of making a new rule in the rename section. Now i can take this code for modeling similar rules.

As for the "Mc" stuff, this ain´t no big deal anyway, i can filter the whole list quickly & do it by inline rename, i just was a bit curious about how this would be handled in Regex. I will have a look in Steve´s tutorial, but must admit, that at this moment Regexes are a bit like reading chinese newspapers for me.