How to remove "everything" between brackets (abc123)?

Advanced Renamer forum
#1 : 14/05-21 20:52
The Jackal
The Jackal
Posts: 4
let's say I have these files:
1- File name (720p).zip
2- File name (3000px2000).zip
3- File name [2 Vid] (5 Sets).zip
4- (Copy) File name [001].zip

How Can I remove any character or digit between brackets "() or []"?
Including the brackets.

So the final result be like = "File Name.zip" .

And it would be much appreciated if you could explain it in some details.

Thanks in advance.


14/05-21 20:52
#2 : 16/05-21 09:56
David Lee
David Lee
Posts: 717
Use two Rename methods...

1) Replace: "(\(|\[)[^\)\]]*(\)|\]) ?"
2) Replace: " $"

Replace with nothing and check "Use regular expressions" in each case and do not include the quotation marks.

Read the basic introduction to regular expressions in the User Guide:
https://www.advancedrenamer.com/user_guide/regul ar_expresions

For an explanation, first consider the removal only of strings within parentheses...

Replace: "\([^\)]*\) ?" with nothing

First note that characters such as "(" and "[" etc have special meanings in a regex and must be "escaped" by prefixing with "\" in order to represent themselves.

Explanation:

"\(" matches an opening parenthesis

"[^\)]*" matches any number of characters except those listed after "^" - ie match everything up to the next ")"

"\)" matches the closing parenthesis

Finally " ?" matches zero or one trailing spaces

This regex will leave an unwanted space at the end of filenames that end within a string within parentheses (ie the additional space that preceded the "("

To remove this use a second replace method with the regex: " $" - where "$" indicates that the space must be followed by the end of the string. (You could also combine the two steps into a single "List replace" method)

To remove strings within brackets we can simply replace "(" & ")" with "[" & "]"
ie Replace: "\([^\)]*\) ?"

However we can combine the two steps into a single regex using the OR metacharacter: "|"
so: "(\(|\[)" will match either "(" or "[" etc
Also add "\]" to the exclusion list ie "[^\)\]]*"

Hence: "(\(|\[)[^\)\]]*(\)|\]) ?"




16/05-21 09:56 - edited 16/05-21 10:03
#3 : 16/05-21 10:44
The Jackal
The Jackal
Posts: 4
Reply to #2:

Wow! You just knocked me off my feet!
Thank you David, Again..
You are always so helpful 👍👍


16/05-21 10:44