#1 2010-04-01 09:19

dodgy
Member
Registered: 2010-04-01
Posts: 9

Remove first out of 3 digits for track numbers

Hi,

Firstly, thanks for a great application. I'm using it to rename various music files as I move them all to my new NAS device.

I've a question, if I have tracks with three digit numbers at the start, how can I drop the first digit, but only for three digit numbers.

For example:

101-track1.mp3
102 - track 2.mp3
103 track 4.mp3
20 - track 20.mp3

Should become:

01-track1.mp3
02 - track 2.mp3
03 track 4.mp3
20 - track 20.mp3

So in other words:

- if a filename doesn't start with numbers, ignore it
- if it starts with two digits, ignore it
- it it starts with three digits, trim the first digit

Many thanks

Offline

#2 2010-04-01 10:46

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Remove first out of 3 digits for track numbers

Right. So I mostly struggle with RegEx, but here's my somewhat pathetic attempt anyway! tongue

Add a RegEx rule and set:

Expression = ^(\d{1})(\d{2})(.*)$

Replace = $2$3

Copy-paste exactly, then Preview first before renaming.

It seems to work, but I'm sure our resident RegEx experts will be along soon to suggest far better ways of doing the same. smile

Cheers!

P.S. The Expression reads as, from L to R - "at start of string (^), if there is 1 digit (\d{1}) followed by 2 digits (\d{2}) followed by anything at all (.*) till the end of the string ($), replace with the 2nd group of characters (2 digits) followed by the 3rd group (all remaining text)".

P.P.S. RegEx is very powerful indeed, so I highly recommend you take a look at the wiki page for the same.

Last edited by Andrew (2010-04-01 10:47)

Offline

#3 2010-04-01 11:50

dodgy
Member
Registered: 2010-04-01
Posts: 9

Re: Remove first out of 3 digits for track numbers

Thanks Andrew for the help, and also for the explanation which was very useful.

I can see a task for me over Easter is to try and get a bit more familiar with RegEx!!!

Offline

#4 2010-04-01 22:15

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

Re: Remove first out of 3 digits for track numbers

Andrew wrote:

Expression = ^(\d{1})(\d{2})(.*)$

Replace = $2$3

Good work Andrew,

this works well, but if you don't mind let's talk about that.

1. you don't need to ()-group what you don't need as replacement, so this works too:
Expression = ^\d{1}(\d{2})(.*)$
Replace = $1$2

2. \d means already ONE digit, so you don't need {1} here:
Expression = ^\d(\d{2})(.*)$
Replace = $1$2

3. and you can shorten the RegEx even more:
Expression = ^\d(\d{2}.*)
Replace = $1


Just my two cents, but you did making the start  smile

EDIT:
ah, i forgot: one may want to take an look at PascalScript rule and use "Serialize duplicates.pas" too
in addition, to prevent error messages on duplicate file names after preview/renameing.
EDIT 2: or
Denis> "Have a look at the Options menu (above files table), there you'll find an option called "Fix confilcting new names"."
(form http://www.den4b.com/forum/viewtopic.php?id=869)

Last edited by Stefan (2010-04-03 10:12)


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

#5 2010-04-02 15:03

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Remove first out of 3 digits for track numbers

Nice Stefan, very nice indeed. smile Since you're one of the "resident RegEx experts" I referred to above, I knew you wouldn't fail to come to the rescue! tongue

Offline

#6 2010-04-03 10:10

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

Re: Remove first out of 3 digits for track numbers

Andrew wrote:

Since you're one of the "resident RegEx experts"

Oh?, thank you  big_smile
There was no need for rescue, so it's fine that you understood the intention of my post  smile


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

Board footer

Powered by FluxBB