Removing Brackets and text except for certain keywords

A swapping-ground for Regular Expression syntax

Removing Brackets and text except for certain keywords

Postby Cypher619 » Tue Mar 05, 2024 6:58 pm

I have a bunch of Japanese Manga and Doujin that I would like to rename. The file names vary in size and can have any number of bracketed text like this

[EROTOMANIA (Nanae)] Ecchi na Gal JK ga Kyokon Zetsurin Oji-san to Pakoru Yatsu [English] [Nisor] [Colorized] [Miss One Life] [Digital] [Decensored].cbz

I would like to lop off all the text in brackets except for [Colorized] and [Decensored]

I have seached through this forum and other regex websites and have managed to come up with this expression that seems to work in regex101.com but it doesn't quite work in BRU

Match: /(\[Colorized\])|(\[Decensored\])|(\[[^()]*?\])/g

This lops off all the bracketed text.

When i put \1 \2 in replace, nothing happens. If I go further and do \3 all the bracketed text returns. That tells me something is not working correctly in my capture groupings or in the interpretation of it in BRU.

I have checked the settings in Regex101 and have set v2 and PCRE >= 7.3 just to make sure I am using compatible statement.

Can someone please help me troubleshoot this?
Cypher619
 
Posts: 7
Joined: Tue Mar 05, 2024 6:40 pm

Exceptions to matching bracketed " [text]"

Postby Luuk » Tue Mar 05, 2024 11:45 pm

With a checkmark inside for "v2", the "Match" can look like...
\ \[(?!Colorized|Decensored)[^][()]*\]/g

The red-part is a negative-lookahead, and says what not to match inside of " [here]".
Could also add (?i) to keep any spellings like colorized or DeCensored.
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: Removing Brackets and text except for certain keywords

Postby Cypher619 » Wed Mar 06, 2024 12:26 am

Thank you!!! This worked very well.


Where would I put the (?i) to catch the mispellings? What would the syntax look like?
Cypher619
 
Posts: 7
Joined: Tue Mar 05, 2024 6:40 pm

Exceptions to matching bracketed " [text]"

Postby Luuk » Wed Mar 06, 2024 1:28 am

Can just insert (?i) at the very beginning of your "Match" to make the whole expression case-insensitive.
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Exceptions to matching bracketed " [text]"

Postby Luuk » Wed Mar 06, 2024 2:59 pm

Im just realized why your original expression wont conduct properly inside of the "Match" box...
Since it always expects a regular-expression, it never uses a leading "/" to say "start-expression".
But it does still need switches like "/g" to say "global", so that its not confused with the letter "g".

So if removing the leading "/" with \1\2 for the "Replace", it conducts much like your description!
You would just need to put 1-space in front of each "\[" so that your spaces will also be matched.

Instead of using (?i), can also use an ending-switch like /gi to make everything case-insensitive.
The (?i) is only better, if you need to turn it off with (?-i) somewhere later in the expression.
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: Removing Brackets and text except for certain keywords

Postby Cypher619 » Thu Mar 07, 2024 5:40 am

Thank you for going through the trouble of seeing where my original regex statement was wrong. It definately helps me and others learn.
Cypher619
 
Posts: 7
Joined: Tue Mar 05, 2024 6:40 pm

Re: Removing Brackets and text except for certain keywords

Postby Cypher619 » Thu Mar 07, 2024 8:50 am

I am using the syntax provided that was provided

\ \[(?!Colorized|Decensored)[^][()]*\]/gi

I noticed that this assumes that there is a leading space before the []. If I remove the leading space it chops the first instance off which is the author which I want to keep. How do I expand this to ignore the first instance of bracketed text?
Cypher619
 
Posts: 7
Joined: Tue Mar 05, 2024 6:40 pm

Exceptions to matching bracketed " [text]"

Postby Luuk » Fri Mar 08, 2024 6:49 pm

Would need to give some examples of now-names ---> new-names.
Without a leading-space, it still removes all [text] except [colorized] or [decensored] or [Any(Text)].
So [EROTOMANIA (Nanae)] should not be modified, unless maybe experimenting with another regex??
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: Removing Brackets and text except for certain keywords

Postby Cypher619 » Fri Mar 15, 2024 1:51 am

Here's a couple of examples. The first group in [] is always the group or author name. The [] that come at the end of the files are comments and there can be any number of them. My examples show 4 but is possible to have 0 - infinity comments. There are other styles of comments that get dropped here but the [] are the biggest. I can figure out how to get rid of the others once I have this working right.


Old Name:
[Unknownmaru] Gimai Kyousei Ninshin (Cyberia Maniacs Kyousei Haramase Project Vol 1)[Colorized] [English] [YxTL] [Digital] [Decensored]

New Name:
[Unknownmaru] Gimai Kyousei Ninshin (Cyberia Maniacs Kyousei Haramase Project Vol 1) [Colorized] [Decensored]

Old Name:
[Kirin Planet] Haha to Musuko no Undoubusoku Kaishouhou [Decensored] [English] [Amoskandy] [Colorized]

New Name:
[Kirin Planet] Haha to Musuko no Undoubusoku Kaishouhou [Decensored] [Colorized]

I'm not to worried about extra spaces at the end of the file/folder names. I know who to deal with those :)

Thanks in Advance for the help
Cypher619
 
Posts: 7
Joined: Tue Mar 05, 2024 6:40 pm

Re: Removing Brackets and text except for certain keywords

Postby Cypher619 » Fri Mar 15, 2024 2:06 am

Here's a couple of examples. The first group in [] is always the group or author name. The [] that come at the end of the files/folders are comments and there can be any number of them. It is possible to have 0 - infinity comments. There are other styles of comments that get dropped here but the [] are the biggest. I can figure out how to get rid of the others once I have this working right.


Old Name:
[Unknownmaru] Gimai Kyousei Ninshin (Cyberia Maniacs Kyousei Haramase Project Vol 1)[Colorized] [English] [YxTL] [Digital] [Decensored]

New Name:
[Unknownmaru] Gimai Kyousei Ninshin (Cyberia Maniacs Kyousei Haramase Project Vol 1) [Colorized] [Decensored]


A case where \ \[(?!Colorized|Decensored)[^][()]*\]/g doesnt work is:

[Sasumata Seven] Chichi no Ecchi na Hanayome Shugyou - Chi-Chi's Naughty Bridal Training (Dragon Ball) [English][Digital]

There's no space between the two sets of comments.

if I edit \ \[(?!Colorized|Decensored)[^][()]*\]/g to \[(?!Colorized|Decensored)[^][()]*\]/g to adjust then I get:

Chichi no Ecchi na Hanayome Shugyou - Chi-Chi's Naughty Bridal Training (Dragon Ball)








Thanks in Advance for the help
Cypher619
 
Posts: 7
Joined: Tue Mar 05, 2024 6:40 pm

Exceptions to matching bracketed " [text]"

Postby Luuk » Fri Mar 15, 2024 10:39 am

For the examples, can just add another exception for [text] to not match at the very beginning.
Can also use ? to make the spaces optional, so the whole "Match" to look something like...
\ ?(?!^)\[(?!Colorized|Decensored)[^][()]*\]/gi

This can rename like the description, but it never adds any spaces if needed?
If they must be added, could instead use a "Match" and "Replace" more like...
(?<=[])])(?=[[(])/g(?X)\ ?(?!^)\[(?!Colorized|Decensored)[^][()]*\]/gi
\ (?X)
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: Removing Brackets and text except for certain keywords

Postby Cypher619 » Fri Mar 15, 2024 10:14 pm

I'll give the first one a try after I download more things.

Thank you again for your help.
Cypher619
 
Posts: 7
Joined: Tue Mar 05, 2024 6:40 pm


Return to Regular Expressions