#1 2021-07-29 20:23

loungebob
Member
Registered: 2015-09-29
Posts: 45

Regex to match square brackets [...]

Trying to get this

Chris Brown - Lil Wayne & Swizz Beatz - Swizz Beatz - Lil Wayne [2009] Graffiti (Expanded Edition)

to this

Chris Brown [2009] Graffiti (Expanded Edition)

using regex.

Find: Chris Brown * \[*\]
Replace: Chris Brown [$2]

How am I doing this wrong? I was so proud of me figuring out I needed to escape the []. but still, not working at all.

Any ideas?

Last edited by loungebob (2021-07-29 20:26)

Offline

#2 2021-07-29 21:15

loungebob
Member
Registered: 2015-09-29
Posts: 45

Re: Regex to match square brackets [...]

Oh I also tried this in Replace.

Offline

#3 2021-07-29 21:19

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

Re: Regex to match square brackets [...]

FROM:
Chris Brown - Lil Wayne & Swizz Beatz - Swizz Beatz - Lil Wayne [2009] Graffiti (Expanded Edition)
TO:
Chris Brown [2009] Graffiti (Expanded Edition)

ToDo:
Find all till first hyphen as subexpression 1 and store for later reuse by $1.
Find all from open squared bracket till the end as subexpression 2 and store for later reuse by $2.

TRY:
https://www.den4b.com/wiki/ReNamer:Rules:RegEx
1) Regular Expressions: Replace expression "(.+? )- .+ (\[.+)" with "$1 $2"


Explanations:
https://www.den4b.com/wiki/ReNamer:Regular_Expressions

(.+? )- >>> match anything non-greedy until space-dash, store for reuse by $1
" .+ " >>>> match space + anything + space, but only till next expression
(\[.+) >>>> match from open bracket anything till the end, store for reuse by $2





You can also use three Subexpressions, where we just drop what was matched by the second subexpression, if that makes more sense to you:
1) Regular Expressions: Replace expression "(.+? )(- .+ )(\[.+)" with "$1 $3"
Chris Brown - Lil Wayne & Swizz Beatz - Swizz Beatz - Lil Wayne [2009] Graffiti (Expanded Edition)

 


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

#4 2021-07-29 22:26

loungebob
Member
Registered: 2015-09-29
Posts: 45

Re: Regex to match square brackets [...]

Oh jeez. I wast even close ??

I’ll try yours in a bit but am sure it does perfect.

Just for giggles. Shouldnt mine have worked when used in Replace (not as a regex)? Wouldnt the first * capture anything after Brown up until the first [ and the second * anything inside the bracket? I realise now I didnt address anything after the brackets but I figured at least the first two wildcard * should have worked…

Offline

#5 2021-07-29 22:59

loungebob
Member
Registered: 2015-09-29
Posts: 45

Re: Regex to match square brackets [...]

OMG! It works, it works! It’s magic and you’re a friggin genius!

Just saved me like a week of headaches ❤️?

Offline

Board footer

Powered by FluxBB