[Solved] Script Rename Regex and Extension

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
GreetingsFromPoland
Posts: 225
Joined: 29 Sep 2022 14:20
Location: Win10 @125%

[Solved] Script Rename Regex and Extension

Post by GreetingsFromPoland »

hi! i am currently using this in my hamburger menu :

Code: Select all

rename r, "-[^-]*$ > .mkv";
and it works great. up to this point all the files i use this on have been MKVs. now i have other extensions as well.

what needs to change in the regex to tell it to leave the existing extension as-is ? right now, i use the command (which works, but renames everything to .mkv), then use the Set Extension option under Rename to set it back.
Last edited by GreetingsFromPoland on 08 Apr 2024 15:02, edited 1 time in total.

highend
Posts: 13338
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script Rename Regex and Extension

Post by highend »

Provide real world renaming examples...

or otherwise, wild guessing:
rename r, "(.*?)(-[^-]*?)(\.[^.]+)$ > $1$3";
One of my scripts helped you out? Please donate via Paypal

GreetingsFromPoland
Posts: 225
Joined: 29 Sep 2022 14:20
Location: Win10 @125%

Re: Script Rename Regex and Extension

Post by GreetingsFromPoland »

hi!
edit you're too fast ! your updated post worked great ! thank you.

as-is, it will rename "01-Introduction-1.mkv" to "01-Introduction.mkv" and it's great (handbrake appends -1, -2, etc. to conversions).

now i am converting to mp4, so "02-Understanding the Effect Hook-2.mp4" becomes "02-Understanding the Effect Hook-2.mkv" due to the mkv setting in the regex rename.
i'd like to have the rename regex just leave the extension alone, regardless of what it is, so :

01-Introduction-1.mkv would be 01-Introduction.mkv
02-Understanding the Effect Hook-2.mp4 would be 02-Understanding the Effect Hook.mp4
03-Effect Dependencies-3.mp3 would be 03-Effect Dependencies-3.mp3

(instead of all them renaming to mkv).

highend
Posts: 13338
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script Rename Regex and Extension

Post by highend »

That's what the regex in my first post does...
One of my scripts helped you out? Please donate via Paypal

Post Reply