#1 2013-01-18 19:42

straxael
Member
Registered: 2013-01-18
Posts: 3

Only stripping/removing specific groups of digits from name

First of all, please forgive my noobishness by posting this new topic as I could not find a similar one. If an answer to my query does exist in an existent topic, please accept my apologies in advance.

Now, I would like to know how I can strip certain groups of numbers from a file name without ReNamer stripping all numerical instances.

For example, the file name below consists of two groups of numbers at the beginning and at the end (highlighted in red). The isolated number at the end of the text (highlighted in blue) is a serialized suffix and is to be kept to maintain the serialization.

263427124_hello everybody_1_992548224

Another issue is that I may only have a group of numbers at the beginning or at the end of a group of files which are appended with serial suffixes, how can I remove both groups of numbers without removing the serialized suffix (example below)?

422426137_hello everybody_2
958136415_hello everybody_3_82429245
hello everybody_4_42582429

I have limited knowledge with using the basic rules of ReNamer and have a few saved presets based on these simpler rules. However, I just can't get my head around RegEx and PascalScript. I will deeply appreciate any help you can give me to solve my problem. Thanks in advance!:)

Last edited by straxael (2013-01-18 19:46)

Offline

#2 2013-01-18 22:44

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

Re: Only stripping/removing specific groups of digits from name

I read you want this:

"how can I remove both groups of numbers without removing the serialized suffix?"


FROM:
263427124_hello everybody_1_992548224
422426137_hello everybody_2
958136415_hello everybody_3_82429245
hello everybody_4_42582429

TO:
_hello everybody_1_
_hello everybody_2
_hello everybody_3_
hello everybody_4_

BUT i guess you want rather this:
hello everybody_1
hello everybody_2
hello everybody_3
hello everybody_4




So an rule could be:
remove leading or trailing groups of 2-or-more digits,
remove then leading or trailing underscores too.



At the moment i can only come up with using three different regex rules at once:
One for leading digits, one for trailing and one for trailing and leading digits.

1) RegEx: Replace expression "^(.+)(_\d{2,})$" with "$1" (skip extension)
2) RegEx: Replace expression "^(\d{2,}_)(.+)$" with "$2" (skip extension)
3) RegEx: Replace expression "^(\d{2,}_)(.+)(_\d{2,})$" with "$2" (skip extension)


That works for your provided examples.
Would not work for files like: 422426137_hello everybody_23. But then again you don't asked for this possibility.


Example removing trailing and leading digits


HTH?


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 2013-01-18 23:32

straxael
Member
Registered: 2013-01-18
Posts: 3

Re: Only stripping/removing specific groups of digits from name

Stefan wrote:

BUT i guess you want rather this:
hello everybody_1
hello everybody_2
hello everybody_3
hello everybody_4

Thanks for the quick response! Yes I would rather have the above, but if you could replace the underscore with a space using RegEx code, so it reads:

hello everybody 1
hello everybody 2
hello everybody 3
hello everybody 4

it would be better! I wouldn't mind having a rule which covers the possibility of a suffix with two digits (hello everybody 10) but I haven't dealt with files (for what I need anyway) with double digit suffixes.

Once again, thank you for helping me! smile

Last edited by straxael (2013-01-18 23:33)

Offline

#4 2013-01-19 00:11

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

Re: Only stripping/removing specific groups of digits from name

straxael wrote:

but if you could replace the underscore with a space using RegEx code, so it reads:

hello everybody 1
hello everybody 2
hello everybody 3
hello everybody 4

it would be better!


Better keep modularity and add an another rule:
4) Replace: Replace all "_" with " " (skip extension)

To add this into the regex too would look to complicated for later maintenance.



I wouldn't mind having a rule which covers the possibility of a suffix with two digits (hello everybody 10)
but I haven't dealt with files (for what I need anyway) with double digit suffixes.

I think for that it would be just enough to match three-or-more digits instead the above used two.



So just change "\d{2,}" to "\d{3,}"

1) RegEx: Replace expression "^(.+)(_\d{3,})$" with "$1" (skip extension)
2) RegEx: Replace expression "^(\d{2,}_)(.+)$" with "$2" (skip extension)
3) RegEx: Replace expression "^(\d{2,}_)(.+)(_\d{3,})$" with "$2" (skip extension)
4) Replace: Replace all "_" with " " (skip extension)



TEST:

FROM:
263427124_hello everybody_1_992548224
422426137_hello everybody_2
958136415_hello everybody_3_82429245
hello everybody_4_42582429

263427124_hello everybody_12_992548224
422426137_hello everybody_23
958136415_hello everybody_32_82429245
hello everybody_42_42582429



TO:
hello everybody 1
hello everybody 2
hello everybody 3
hello everybody 4

hello everybody 12
hello everybody 23
hello everybody 32
hello everybody 42




Once again, thank you for helping me! smile

You are welcome. Maybe you can help Denis too?


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 2013-01-19 00:24

straxael
Member
Registered: 2013-01-18
Posts: 3

Re: Only stripping/removing specific groups of digits from name

Thanks again! I know I was biting off more than I could chew by requesting the removal of all underscores; I have done as you suggested and confined it to a separate rule. I have adjusted the code from "\d{2,}" to "\d{3,}" just in case of the possibility.

ReNamer has helped me immensely by renaming large bulk files and I will gladly donate to Denis once I have set up Paypal; as with RegEx I have never used it!

Offline

#6 2013-03-12 22:40

tosh9i
Member
Registered: 2013-03-12
Posts: 7

Re: Only stripping/removing specific groups of digits from name

I'm in a similar situation.  However, there are some letters grouped in with the numbers. For example:
Home_04_D3698125
Home_05_Ad19bba9
Home_06_64a2bd19
Home_07_F6s6eh77

Silent_Call_J392ls09_01
Silent_Call_O33o041_02
Silent_Call_356d231_03

I just want to strip away that alphanumeric stuff and have it look like this:
Home_04
Home_05
Home_06
Home_07

Silent_Call_01
Silent_Call_02
Silent_Call_03

I have over a thousand files like this.  I know I can remove them group by group, but I'd still have to do it about 40 times.  I prefer doing it all at once.

Offline

#7 2013-03-13 07:45

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

Re: Only stripping/removing specific groups of digits from name

tosh9i wrote:

I'm in a similar situation.  However, there are some letters grouped in with the numbers. For example:
Home_04_D3698125
Home_05_Ad19bba9
Home_06_64a2bd19
Home_07_F6s6eh77
[...]

That is a little bit harder if there are mixes of patterns in your file names. Sometimes it's usual to find file1.ext and this does not mean it's a wrong name.

But following the pattern in your name I would do it with something like:
RegEx: Replace expression "_?[0-9A-Z]*([A-Z]+[0-9]+|[0-9]+[A-Z]+)[0-9A-Z]*(_?)" with "$2" (skip extension)


Trying to do it for a more general purpose, even if it gives less matches than the one above, I would prefer to do it this way
RegEx: Replace expression "[0-9A-Z]*([A-Z]+[0-9]+[A-Z]+|[0-9]+[A-Z]+[0-9]+)[0-9A-Z]*" with "" (skip extension)
RegEx: Replace expression "_+" with "_" (skip extension)  // Clean "text___text" to "text_text"
RegEx: Replace expression "_$" with "" (skip extension) // Clean "file_.ext" to "file.ext"


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

Offline

#8 2013-03-13 08:08

tosh9i
Member
Registered: 2013-03-12
Posts: 7

Re: Only stripping/removing specific groups of digits from name

thanks, I'll give it a try and let you know.

Offline

#9 2013-03-14 01:41

tosh9i
Member
Registered: 2013-03-12
Posts: 7

Re: Only stripping/removing specific groups of digits from name

SafetyCar wrote:
tosh9i wrote:

I'm in a similar situation.  However, there are some letters grouped in with the numbers. For example:
Home_04_D3698125
Home_05_Ad19bba9
Home_06_64a2bd19
Home_07_F6s6eh77
[...]

That is a little bit harder if there are mixes of patterns in your file names. Sometimes it's usual to find file1.ext and this does not mean it's a wrong name.

But following the pattern in your name I would do it with something like:
RegEx: Replace expression "_?[0-9A-Z]*([A-Z]+[0-9]+|[0-9]+[A-Z]+)[0-9A-Z]*(_?)" with "$2" (skip extension)


Trying to do it for a more general purpose, even if it gives less matches than the one above, I would prefer to do it this way
RegEx: Replace expression "[0-9A-Z]*([A-Z]+[0-9]+[A-Z]+|[0-9]+[A-Z]+[0-9]+)[0-9A-Z]*" with "" (skip extension)
RegEx: Replace expression "_+" with "_" (skip extension)  // Clean "text___text" to "text_text"
RegEx: Replace expression "_$" with "" (skip extension) // Clean "file_.ext" to "file.ext"


Works like a charm, thanks.

Offline

Board footer

Powered by FluxBB