Delete everything in Brackets without numbers

A swapping-ground for Regular Expression syntax

Delete everything in Brackets without numbers

Postby roderh » Sat Oct 17, 2015 1:00 pm

Hi all,

please help me with this problem: In file-names I want to delete brackets and all charakters in it without brackets, that contain only numbers, e.g.:

"Test-file (just-some_Text) (2015) (123 pages).txt" should become: "Test-file (2015).txt"


with the help of this post: http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=189&start=0W
I was able to to this "( \(.*\))", but this just deletes everything.

Thank you in advance!
roderh
roderh
 
Posts: 3
Joined: Sat Oct 17, 2015 12:44 pm

Re: Delete everything in Brackets without numbers

Postby Stefan » Sat Oct 17, 2015 2:00 pm

Hi roderh,


FROM:
Test-file (just-some_Text) (2015) (123 pages).txt
TO:
Test-file (2015).txt

TRY this:

Works only with files with same order of Brackets: xxx (garbage) (digits) (garbage)
If you have files with different pattern, you would need several such steps, or best utilize a scripting language.

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

Step 1 - protect Brackets with numbers only:

RegEx(1)
Match: (.+)\((\d+)\)(.+)
Repla: \1[\2]\3
[Rename]

You get:
Test-file (just-some_Text) [2015] (123 pages).txt

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

Step 2 - remove Brackets with garbage

RegEx(1)
Match: (.+) \(.+\)(.+) \(.+\)
Repla: \1\2
[Rename]

You get:
Test-file [2015].txt

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

Step 3 - replace [] back to ()


RegEx(1)
Match: (.+)\[(\d+)
Repla: \1(\2)
[Rename]

You get:
Test-file (2015).txt

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

Done.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Delete everything in Brackets without numbers

Postby roderh » Sun Oct 18, 2015 12:49 pm

Thank you very much for your fast and thorough reply!
Greetings!
roderh
 
Posts: 3
Joined: Sat Oct 17, 2015 12:44 pm

Re: Delete everything in Brackets without numbers

Postby Stefan » Sun Oct 18, 2015 2:16 pm

Oh, sorry :roll:

Of course my solution was silly (I guess first I wanted to walk another, a more universal way)


FROM:
Test-file (just-some_Text) (2015) (123 pages).txt
TO:
Test-file (2015).txt


TRY this (Only 1 step need, just drop the garbage):

RegEx(1)
Match: (.+) \(.+\)(.+) \(.+\)
Repla: \1\2
[Rename]


You are left with:
Test-file (2015).txt


----------------------------------------------------------------
Works only with files with same order of Brackets: xxx (garbage) (digits) (garbage)
If you have files with different pattern, you would need several such steps, or best utilize a script language.
----------------------------------------------------------------

.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Delete everything in Brackets without numbers

Postby roderh » Sun Oct 18, 2015 5:50 pm

Thank you very much again! Thats less work!
roderh
 
Posts: 3
Joined: Sat Oct 17, 2015 12:44 pm


Return to Regular Expressions