MRT: a Regex question, how to do not match that many

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Hakker
Junior Member
Junior Member
Posts: 23
Joined: 2009-03-01, 14:48 UTC

MRT: a Regex question, how to do not match that many

Post by *Hakker »

I'm trying to figure out a regex solution to get the following working on some files I have

[Clive Barker] Rawhead Rex.cbz
[Hastings] I Am Groot 001 (2017-)(FromAnime).cbr
[Robinson] Cable 001 (2017-)[FromAnime].cbr

My plan is to get
Clive Barker\[Clive Barker] Rawhead Rex.cbz
Hastings\[Hastings] I Am Groot 001 (2017-)(FromAnime).cbr
Robinson\[Robinson] Cable 001 (2017-)[FromAnime].cbr

however some have double backets and others don't and that where I hit my snag.

searching: ^\[(.*)\].*
replace with: $1\\$0

results in:

Clive Barker\[Clive Barker] Rawhead Rex.cbz
Hastings\[Hastings] I Am Groot 001 (2017-)(FromAnime).cbr
Robinson] Cable 001 (2017-)[FromAnime\[Robinson] Cable 001 (2017-)[FromAnime].cbr

I tried various combinations however i never can seem to get it group only the first set of brackets. It's always grouping basically the entire string even when encapsuling everything in parenthesis. tried combinations with only the first 20 characters, but failed to get that working. The point is i'm bad at regex.
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

MUT: a Regex question: how to match non-greedy

Post by *Stefan2 »

Use your .* expression in a non-greedy variant



An ? will switch-on the non-greedy operation:

searching: ^\[(.*?)\]
replace with: $1\\$0


 
Hakker
Junior Member
Junior Member
Posts: 23
Joined: 2009-03-01, 14:48 UTC

Re: a Regex question

Post by *Hakker »

ugh see that's what I mean.... I'm bad at regex.

Thank you for the solution.
Post Reply