Text between square brackets

A swapping-ground for Regular Expression syntax

Text between square brackets

Postby thatsit » Wed Jan 14, 2015 11:13 pm

Hi all!

I just have a problem with the regular expressions in the Bulk Rename Utility.

I want to kill a string in a fille name (or replace the string). The string is as follows:

Hard To Say I'm Sorry 2K9 [Radio Edit]Radio Edit
It Just Won't Do [Bigroom Radio Edit]Bigroom Radio Edit
Music Matters Feat. Cass Fox [Axwell Edit]Axwell Edit
Memory [Klaas Mix]Klaas Mix

And it should be:

Hard To Say I'm Sorry 2K9 (Radio Edit)
It Just Won't Do (Bigroom Radio Edit)
Music Matters Feat. Cass Fox (Axwell Edit)

and so on.

First I have tried to use
Code: Select all
\[.*\]
to select the square brackets and the text between them and replace them with a test string first. But this does not work.

The second problem is to get the killed information without the square brackets into the normal brackets. But about this...I have NO idea :D

Can somebody help me out?
thatsit
 
Posts: 1
Joined: Wed Jan 14, 2015 11:01 pm

Re: Text between square brackets

Postby TheRegExpMaster » Thu Jan 15, 2015 6:12 am

Hi, you can try this :P

RegEx(1)
MATCH :
Code: Select all
(.+)\[(.+)\].+
REPLACE :
Code: Select all
\1(\2)

Hard To Say I'm Sorry 2K9 [Radio Edit]Radio Edit.mp3 will be renamed Hard To Say I'm Sorry 2K9 (Radio Edit).mp3
It Just Won't Do [Bigroom Radio Edit]Bigroom Radio Edit.mp3 will be renamed It Just Won't Do (Bigroom Radio Edit).mp3
Music Matters Feat. Cass Fox [Axwell Edit]Axwell Edit.mp3 will be renamed Music Matters Feat. Cass Fox (Axwell Edit).mp3
Memory [Klaas Mix]Klaas Mix.mp3 will be renamed Memory (Klaas Mix).mp3

But be aware that the regex cannot check if the text inside the brackets is the same as the one afterwards. So :
Memory [Klaas Mix]Hellooooooooooworld.mp3 will be renamed Memory (Klaas Mix).mp3

Also, the file name must have a string before the brackets, inside the brackets and after the brackets (if you want to allow empty strings, use ".*" instead of ".+"). So :
[Klaas Mix]Klaas Mix.mp3 will be unchanged
Memory [Klaas Mix].mp3 will be unchanged
Memory []Klaas Mix.mp3 will be unchanged
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm


Return to Regular Expressions