Remove all brackets and what it contains except...

A swapping-ground for Regular Expression syntax

Remove all brackets and what it contains except...

Postby penguinaka » Fri Jun 10, 2011 8:13 am

Hi, I'm renaming a large database of ebooks (in the thousands) before I import them into a library management software. Below is some examples of filenames.

Before:
George Carlin - Funny Jokes 1 - Your Mama! (reprint) (v1.5).epub
George Carlin - Funny Jokes 1 - Your Mama! (funny jokes 123) (v3.2) (mobi).mobi
George Carlin - Funny Jokes 1 - Your Mama! (v5.0) (pdf).pdf

What i'm trying to accomplish is the removal of any brackets and the infomation it contains unless the bracket is a version number (i.e. begins with a v)... in this instance the files would look like this when it is done.

After:
George Carlin - Funny Jokes 1 - Your Mama! (v1.5).epub
George Carlin - Funny Jokes 1 - Your Mama! (v3.2).mobi
George Carlin - Funny Jokes 1 - Your Mama! (v5.0).pdf

Any help would be appreciated. thanks in advance.
penguinaka
 
Posts: 4
Joined: Fri Jun 10, 2011 7:56 am

Re: Remove all brackets and what it contains except...

Postby Stefan » Sat Jun 11, 2011 11:29 pm

Hi and welcome!

Lets see how we can solve this.


First make an backup of all your files, then test with an few files how it works.

Note that this solution works only for files like the examples you have provided.
If one file is for example in the format like
George Carlin - Funny Jokes 1 - Your Mama! (v5.0) other text.pdf
then my pattern may fail.

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

STEP 1 - escape (vX.x) to [vX.x] and remove first ()-groups

FROM:
George Carlin - Funny Jokes 1 - Your Mama! (funny jokes 123) (v3.2) (mobi).mobi
George Carlin - Funny Jokes 1 - Your Mama! (reprint) (v1.5).epub
George Carlin - Funny Jokes 1 - Your Mama! (v5.0) (pdf).pdf

TO:
George Carlin - Funny Jokes 1 - Your Mama! [v3.2] (mobi).mobi
George Carlin - Funny Jokes 1 - Your Mama! [v1.5].epub
George Carlin - Funny Jokes 1 - Your Mama! [v5.0].pdf

DO:
RegEx(1)
Match: (.+)\((v.+?)\)(.*)
Repla: \1[\2]\3

Remove(5)
Crop Special: (*)
[X] D/S

Select a few or all files in "Name"-column to see the preview in "NewName"-column.
If all went fine, press at
[Rename]

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

STEP 2 - remove second ()-groups

TO:
George Carlin - Funny Jokes 1 - Your Mama! [v3.2].mobi
George Carlin - Funny Jokes 1 - Your Mama! [v1.5].epub
George Carlin - Funny Jokes 1 - Your Mama! [v5.0].pdf

DO:
[Rename]
Press rename an second time to remove second (...)-group from first example.
Maybe you have to press rename some more times till all () are gone.

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


STEP 3 - back from [vX.x] to (vX.x)

TO:
George Carlin - Funny Jokes 1 - Your Mama! (v3.2).mobi
George Carlin - Funny Jokes 1 - Your Mama! (v1.5).epub
George Carlin - Funny Jokes 1 - Your Mama! (v5.0).pdf

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

[Rename]

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

Re: Remove all brackets and what it contains except...

Postby penguinaka » Sat Jun 11, 2011 11:41 pm

Thank you so much for replying! and also the welcome :) Question:

sometimes the files will look like this without the series info or the series sometimes is in brackets to like this:

George Carlin - [Funny Jokes 01 ] - Your Mama (reprint) (v5.0) (mobi).mobi
George Carlin - (Funny Jokes 01 ) - Your Mama (reprint) (v5.0) (mobi).mobi

or no series info

George Carlin - Your Mama (reprint) (v5.0) (mobi).mobi

.... does it ignore that and can handle it or do i need to do a find and replace on the series brackets like *edit just saw that it doesn't

find - [ replace with -
find ] - replace with -
find ) - replace with -
find - ( replace with -
then replace - - with -
(this is how i've been removing it usually) (bunch of steps i know ugg) lol

also will it still work without the series in it? *just saw that it does

Thank you much :) I have another one for you.. I'll start that one in a new post for the benefit of anyone doing a search.
penguinaka
 
Posts: 4
Joined: Fri Jun 10, 2011 7:56 am

Re: Remove all brackets and what it contains except...

Postby penguinaka » Sun Jun 12, 2011 12:52 am

It works like a charm!!! I just need to remove any series brackets prior to use. Rock and Roll!
penguinaka
 
Posts: 4
Joined: Fri Jun 10, 2011 7:56 am


Return to Regular Expressions