#1 2020-03-25 03:57

Incubus
Member
Registered: 2020-03-25
Posts: 2

Remove last 4 digits

hello,
i have a problem with RegEx.
i have a huge list of files, and some of them end with 4 numbers.
I think that's easy to do, but i can't find how i can remove the last 4 caracters only if they are 4 numbers...

If someone has an idea smile
Thanks ^^

Offline

#2 2020-03-25 18:57

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Remove last 4 digits

You are missing a couple of examples of input and desired output filenames.

The exact rule might differ depending on the specifics of your input filenames, but here is a good start for you:

Regular Expressions rule - Replace expression "\d{4}\Z" with "" (skip extension)

For the reference:
https://www.den4b.com/wiki/ReNamer:Regular_Expressions

Offline

#3 2020-03-25 19:00

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Remove last 4 digits

Incubus wrote:

hello,
i have a problem with RegEx.
i can't find how i can remove the last 4 caracters only if they are 4 numbers...


Hi and welcome,


>>> i have a huge list of files, and some of them end with 4 numbers.
Else you could just use the Delete rule (https://www.den4b.com/wiki/ReNamer:Rules:Delete) with "Right-to-left" (from the end) option.

see  http://www.den4b.com/wiki/ReNamer:Regular_Expressions

\d ==>    a numeric character
\Z ==>    end of text ($ is an alternative)
{n} ==>    exactly n times



FROM:
Test.txt
Test 1.txt
Test 12.txt
Test 123.txt
Test 1234.txt
Test 1234 Kopie.txt

TO:
Test.txt
Test .txt
Test 1.txt
Test 12.txt
Test 123.txt
Test 1234 Kopie.txt


USE RegEx: 
http://www.den4b.com/wiki/ReNamer:Rules:RegEx
Expression: "\d{4}$"
Replace: "" (skip extension)

Explanation:
"\d{4}$" means four times \d ==> \d\d\d\d , matched at the very end ==> $


Adjust the Expression to your need.
For example also match and remove the empty space in front of the four digits >>> Expression: " \d{4}$"


Additionally enable "Options > Fix conflicting new names"
http://www.den4b.com/wiki/ReNamer:Options_menu


Fine?


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#4 2020-03-26 02:29

Incubus
Member
Registered: 2020-03-25
Posts: 2

Re: Remove last 4 digits

wow, thank you ! smile that works... the regex seems so easy once you see it hmm

Offline

Board footer

Powered by FluxBB