#1 2010-02-03 06:05

kbarry64
Member
Registered: 2010-02-03
Posts: 3

Remove leading numbers

I was wondering if there's a way to remove leading numbers until the first alphabetic character.  I'm trying to organize my photos, but quite a few of them have leading random numbers added to them.  As in:

12345This_is_a_filename.jpg
But_So_Is_This.jpg
345_This_Is_one_too.jpg
56789012 Lets Not Forget this.jpg
11111-And lastly this.jpg

What I'd like to do is delete until the first alphabetic character.  If the first character is alphabetic, nothing would happen.  I've tried the delete until delimiter, but without luck.  It can probably be done with regular expressions, but I'm not familiar with them.

Any help would be greatly appreciated.

Thank you,

Kevin

Offline

#2 2010-02-03 07:26

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

Re: Remove leading numbers

kbarry64 wrote:

I was wondering if there's a way to remove leading numbers until the first alphabetic character.  I'm trying to organize my photos, but quite a few of them have leading random numbers added to them.  As in:

12345This_is_a_filename.jpg
But_So_Is_This.jpg
345_This_Is_one_too.jpg
56789012 Lets Not Forget this.jpg
11111-And lastly this.jpg

What I'd like to do is delete until the first alphabetic character.  If the first character is alphabetic, nothing would happen.  I've tried the delete until delimiter, but without luck.  It can probably be done with regular expressions, but I'm not familiar with them.

Any help would be greatly appreciated.

Thank you,

Kevin

Hi Kevin, welcome.

Remove leading digits

I would use regular expressions (RegEx/RegExp/RE) for this issue.

That's it:
Split your file names into parts, use backreference grouping ()'s  for the parts you wanna keep,
then build your new name with this kept parts only, dropping the unwanted parts.

FROM:
But_So_Is_This.jpg
345_This_Is_one_too.jpg
11111-And lastly this.jpg
12345This_is_a_filename.jpg
56789012 Lets Not Forget this.jpg
TO:
But_So_Is_This.jpg
_This_Is_one_too.jpg
-And lastly this.jpg
This_is_a_filename.jpg
  Lets Not Forget this.jpg

That's it:
Find one-or-more digits, followed by the rest.

Add Rule RegEx:
Expression: \d+(.+)
Replace: $1


To make this ()'s and $n's more clear:
Expression: (\d+)(.+)
Replace: $2
Here is search for one-or-more digit and group this by ()'s, then i search for the rest and group this too.
Then i want only what is in group 2 back as new name, that's why i use $2 here - to refer to backreferencing group 2.
Since i didn't been interested into the leading digits - i don't have to group them for
back referencing, that's why \d+(.+) is enough.
Hope my explanations makes sense to you.



-------------------


But i guess you want more an result like:
But_So_Is_This.jpg
This_Is_one_too.jpg
And lastly this.jpg
This_is_a_filename.jpg
Lets Not Forget this.jpg


That's it:
Find one-or-more digits, followed by one-or-none from an pool of blank/dash/underscore, followed by the rest.

Add Rule RegEx:
Expression: \d+[- _]?(.+)
Replace: $1

-------

See the WIKI for more about this:
=> http://www.den4b.com/wiki/ReNamer:Rules for more about using Rules and
=> http://www.den4b.com/wiki/ReNamer:Regular_Expressions for more about the RegEx Syntax.


HTH?  big_smile
If yes spread the word about ReNamer ... and help two others too.

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


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

#3 2010-02-03 23:05

kbarry64
Member
Registered: 2010-02-03
Posts: 3

Re: Remove leading numbers

Thank you, that's a great start.  Only problem I found was that it removes the first set of digits even if it's not in position 1.

i.e.  PictureFrom2009Cookout.jpg --> PictureFromCookout.jpg

But, I'll take a look at the Regular Expression Wiki and see if I can work it out.

Thanks again,

Kevin

Offline

#4 2010-02-04 09:14

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

Re: Remove leading numbers

kbarry64 wrote:

Thank you, that's a great start. 
Only problem I found was that it removes the first set of digits even if it's not in position 1.

i.e.  PictureFrom2009Cookout.jpg --> PictureFromCookout.jpg

kbarry64 wrote:

I was wondering if there's a way to remove leading numbers until the first alphabetic character.
As in:

It's always an good idea to provide all possibilities of file name pattern in question.
That would give the supporter an change to do it right  wink

But it was my fault not to match the whole string with my first try.
O.K., so we search now for leading digits from start of the file name only:
Add Rule RegEx:
Expression: ^\d+[- _]?(.+)
Replace: $1


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-02-05 05:15

prologician
Member
Registered: 2009-01-30
Posts: 84

Re: Remove leading numbers

I myself just read over this thread for the first time just now, and for all the thought and care that Stefan put into this, I think that there's a much easier way:

Expression: ^[^a-zA-Z]*
Replace: (Nothing)

That is to say... look for a block of non-alphabet letters that starts at the beginning and goes as far as it can, and replace that with nothingness. Which, looking back at your original post, seems to describe exactly what you're looking for.

Yes, it's not as precise as Stefan's. But it's a different way of looking at things. smile

Offline

#6 2010-02-05 12:05

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

Re: Remove leading numbers

In my opinion this is the best suited RegEx:

Expression: ^\d*[-_\s]*
Replace: (nothing)

This will remove all leading digits and following dashes, underscores and spaces.

prologician, he wanted to leave digits anywhere else except the beginning intact.

Offline

#7 2010-02-05 13:47

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

Re: Remove leading numbers

den4b wrote:

prologician, he wanted to leave digits anywhere else except the beginning intact.

prologician solution works as expected too, so does Denis one.

Expression: ^[^a-zA-Z]*
Replace: (Nothing)
Find none-or-more leading signs which are not A,B,C,...Z or a,b,c,...z

Expression: ^\d*[-_\s]*
Replace: (nothing)
Find none-or-more leading digits, followed by none-or-more dashes, underscores or spaces.


Isn't RegEx fun?


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

#8 2010-02-05 14:06

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

Re: Remove leading numbers

Oops, didn't notice that ^ he had in front roll , without which everything else except alphabetic characters would be stripped in the entire file name.

My version is still better big_smile , because prologician's version will strip all non-Latin alphabetic characters, meaning his version is Latin/English only.

Offline

#9 2010-02-05 15:08

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Remove leading numbers

Another option/improvement for cases with dashes between the numbers:

Expression: ^[\d-_\s]*
Replace: (nothing)

big_smile

Like Stefan said:

Stefan wrote:

Isn't RegEx fun?


If this software has helped you, consider getting your pro version. :)

Offline

#10 2010-02-05 16:09

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

Re: Remove leading numbers

SafetyCar wrote:

Expression: ^[\d-_\s]*
Replace: (nothing)

:thumpsup:  smile
The cleverest till now.

den4b wrote:

will strip all non-Latin alphabetic characters, meaning his version is Latin/English only.

Ah, i see. Since i didn't have to deal with such, i simple don't think about that. Thanks for the reminder.


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