#1 2022-01-27 20:36

Hans
Member
Registered: 2020-11-03
Posts: 4

Move filepart with parentheses to end of filename

My issue has similarities with another earlier topic on this forum, I think:
https://www.den4b.com/forum/viewtopic.php?id=464

I tried to use that case as a starting point, but I still have some questions.


First, some examples of my files/filename-structure. Spaces are real spaces in the filename-structure.
The (...) part can be at every position in the filename and can be of different 'size'/'length'.
Dashes are here and there, random.

Example 1:
abc - defg hi (1234) jklm.extention

Example 2:
abcde fg - (123456) hijklmn op.extention

Example 3:
abc fghi (123) - klmn op qr.extention


The goal is to move every part starting with ( and ending with ) to the end of the filename, dispite of its position and length/amount of characters 'inside' the ( and )
Note: right in front of ( a space should be placed.


'Output' should be like this:

Example 1:
abc - defg hi jklm (1234).extention

Example 2:
abcde fg - hijklmn op (123456).extention

Example 3:
abc fghi - klmn op qr (123).extention



My problem here are the parentheses characters. In the formula mentioned in the similar case/issue on this forum, the ( and ) are used as 'formula'-characters... and in my filename the both ( and ) are just parentheses / alphanumeric characters, used to make the characters inside the ( ) a bit more 'visible' and nothing more than that.


Thanks in advance for help / advice!


Greetings,

Hans

Last edited by Hans (2022-01-27 20:37)

Offline

#2 2022-01-27 21:19

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

Re: Move filepart with parentheses to end of filename

FROM:
abc - defg hi (1234) jklm.ext
abcde fg - (123456) hijklmn op.ext
abc fghi (123) - klmn op qr.ext

TO:
abc - defg hi jklm (1234).ext
abcde fg - hijklmn op (123456).ext
abc fghi - klmn op qr (123).ext

USE:
Regular Expressions:
Expression:(.+)(\(.+\))(.+)
Replace with: $1$3 $2
(skip extension)



.


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 2022-01-28 08:36

Hans
Member
Registered: 2020-11-03
Posts: 4

Re: Move filepart with parentheses to end of filename

Hi Stefan,

thank you very much for the quick response and a solution.

Your Regular Expression works, but there is one tiny thing.
The removed (...) part 'leaves' one space extra where it was before the Expression. And yes, this can be explained: the (...) part has/had a space before it and after it.

Before the Expression:
ABCspaceDEFGspace(12345)spaceHIJK.extention

After the Expression:
ABCspaceDEFGspacespaceHIJKspace(12345).extention

Ok, I can make another extra simple Replace-action by saying 'Replace spacespace by space'...
But can this be accomplished 'inside' your Expression?

Greetings,
Hans

Offline

#4 2022-01-28 10:05

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

Re: Move filepart with parentheses to end of filename

Hi Hans

you may want to try to use <> code tag so you can preserve formatting:

ABC DEFG (12345) HIJK.extention
ABC DEFG  HIJK(12345).extention
ABC DEFG HIJK (12345).extention
ABC    DEFG    HIJK    (12345).extention


Just add an space to match but not to store for reuse in your RegEx expression:
Expression: (.+)(\(.+\))(.+) <<old
Expression: (.+) (\(.+\))(.+) <<new with space


Else the "greedy" expression ".+" will take everything up to the opening parenthesis, including that space.
Now we say: give me all , till a space , till a ( , all , till a ) , all


The Replace pattern stays the same:
Replace with: $1$3 $2
(skip extension)




You can play around with regex, add or remove an space or add an sign like # to see what happens in the Preview.
Replace with: $1 # $3 # $2
So you understand regex and how it works over time.



.


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