Rename Help with interesting difficult regEx patterns

Hi guys, I hope you can help me with some interesting rename patterns. Here's my request.

1. Clean multiple spaces or underscores.
I found this awesome scripts in this thread Various simple rename presets which does just fine, except that it doesn't remove a space at the end. And it would be great if it would affect both underscores and spaces. Integrated with the Underscores to spaces preset.

How__to___rename.txt
How to rename.txt

2. Seperate words by recognizing cases. (even if the first word does not start with a case)

  1. howToRename.txt
  2. How To Rename.txt

3. Make only extension lowercase. I have the preset called Capitilize words but it also effects filename before the file extension.

How to RENAME.TXT
How to RENAME.txt

4. Find specific character and replace (in this example: find the second dot and replace with a space+dash)

1.04. How to rename.txt
1.04 - How to rename.txt

5. I figured out the following example, but that is as far as I got. (.+)-(.+)(.[^.]+) to \1\3
How to rename-1.txt
How to rename.txt

It would be awesome to have these as presets. And I'm sure more people would benefit from such presets. Thanks in Advance.

[quote="OpelOpus"]3. Make only extension lowercase. I have the preset called Capitilize words but it also effects filename before the file extension.

How to RENAME.TXT
How to RENAME.txt
[/quote]

That one is quite easy:

RENAME CASE=extlower

Try my Dynamic Renamer. It makes these really easy, and you can save them as presets. Here are the "New name" values that solve your problems 1 - 5:

  1. -/{2,}/ /g -///g

  2. -/([a-z])([A-Z])/$1 $2/g -ct

  3. -sl

  4. -/. / - /

  5. -/-\d+//

And you can add additional transformations if you wanted. For example, your number 5 changes the 1st one here to the 2nd one:

How to rename-1.txt
How to rename.txt

If you now wanted to title case that name, just add -ct to to #5 answer:

-/-\d+// -ct

or if you didn't want the "To" to be uppercased (because it is a preposition):

-/-\d+// -cT

Hi OpelOpus!

Just for fun, in addition to abr's suggestion: here are some regexes you can save as presets.

How__to___rename.txt => How to rename.txt
Regex mode
Old name: *([^]+)_+(.*)#
New name: \1 \2
No need to check any of the boxes

  1. howToRename.txt => 02. How To Rename.txt
    Regex mode
    Old name: (.?)([a-z]+)(?=[A-Z])(.)#
    New name: \1\2 \3
    Check the "Case Sensitive" and "Modify Capitalization: Capitalize all words" boxes

How to RENAME.TXT => How to RENAME.txt
Regex mode
Old name: (.*)
New name: \1
Check the "Modify Capitalization: Lower-Case Extension" box

1.04. How to rename.txt => 1.04 - How to rename.txt
Since you want to replace "specific characters", you will need some knowledge of regex to adapt the saved pattern for every case.
Regex mode
Old name: ([^.]+).([^.]+).(.*)
New name: \1.\2 -\3
No need to check any boxes.

How to rename-1.txt => How to rename.txt
Regex mode
Old name: (.*)-\d(.[^.]+)
New name: \1\2
No need to check any boxes.

Let me know if you have any questions!

I meant, abr and MrC.

Thank you very much guys. Really appreaciate your help.

@MrC. That looks like a powerful tool! I installed activePerl than I placed the orp file in Appdata under rename presets, but it doesn't show up. Should I do something in ActivePerl first?

@Playful
Example 1 still doesn't remove a space at the end. And is it possible the same rule addresses both multiple underscores and spaces?

Example 2 did not work for me.

Example 4. "Since you want to replace "specific characters", you will need some knowledge of regex to adapt the saved pattern for every case."
Thats indeed the difficult part. Is there a way to just address the 4th character with regex? Say if I just want the 4th character and replace it with x?

Merci!

No, just import the orp via the Rename dialog, File > Import.

No, just import the orp via the Rename dialog, File > Import.[/quote]

Yes that worked. Brilliant! Especially for example 2, I thought that one was pretty though. Thank you so much! Im going to study this Dynamic Renamer and see if I can use it without help in the future.
:thumbsup:

Hi OpelOpus!

Did you check the boxes I mentioned?
Please see the screenshot below and the old name / new name.

Easy. :slight_smile:
1234morestuff.stuf => 123xmorestuff.stuf
Old name: ^(.{3}).(.*)
New name: \1x\2

You're right, I missed that.
Regex mode
Old name: ^*([^]+)+(.*)*(.[^.]+)#
New name: \1 \2\3
No need to check any of the boxes

Let me know if you have any questions. :slight_smile:

Hello Playful,

Still no succes. See my attachments. Maybe its because I have an older version of opus? (9.5.6.0)





Hi OpelOpus!

On your first screenshot, please note that you said you wanted to replace the fourth character with x:

Your original filename already contains "x" as the fourth character, so there is no change (x is changed into x). To change the fourth character to "y" in the file name, change the x to a y in the replacement string:
\1y\2

For your second screenshot... I must have been asleep when I wrote to you (first thing in the morning). I was missing one character. Please see attached screenshot.
^*([^]+)+(.*?)*(.[^.]+)#
\1 \2\3

For your last screenshot... It beats me. Please have a look at the "comp" screenshot below. Do you see any difference? I don't think I see one. A good question for someone with keener eyes. Maybe we're missing a setting somewhere.
Or could it be that one of the characters in your file name is some unicode character that looks exactly like ascii but is not ascii? That can happen with foreign locales. To give you an example, there are several ways to encode "é".



Make sure Preferences / Miscellaneous / Advanced: regex_style is not set to the legacy Opus 9 mode.

Ah, OpelOpus, I was sure that if Leo had a look he would detect the problem. Brilliant!

Is that working for you with that different setting?

If OpelOpus is using Opus 9 then the legacy regex is his only option.

Guys, I don't have that option legacy option.

But no worries. For now I'll use MrC's dynamic rename. Im really grateful for your time and help. Great community!
Im planning on upgrade when opus 11 releases, so maybe then I get to play with new regex and more stuff.


Good one OpelOpus, I'm sure you'll love Opus 11. :thumbsup:

@OpelOpus - I'm glad you like the tool. I find it very useful, and use it frequently. It is pretty easy to build up very complex renames with a few simple chained options.

Yesterday I solved part 1 of a long-standing problem, and just a few minutes ago I solved part 2:

Perlscript & Unicode problem [Solved]

These fixes will go into a new version of Dynamic Renamer, which I'll put out tomorrow. In a nut shell, the fixes will allow certain tricky Unicode characters to be processed by Directory Opus correctly (the thread above mentions the character "ţ" (latin small t with cedilla), which in your version of Dynamic Renamer will get treated as a "t" (small t).

EDIT: I've updated the script to version 1.9.