#1 2022-11-04 09:04

Dokkaebi
Member
Registered: 2022-11-04
Posts: 3

Is there a way to disable the wildcard function for the brackets?

When creating a rule I selected the option that questionmark, squared bracket and asteriks behave like a wildcard. The problem is when I have filenames with squared brackets I can't replace them when I also want to use wildcards in the replacement rule.

For example in Foobar2000 there is the 'xxxx' character (wihtout the xxxx) that forces any character between it to lose all it's special functions and just act as a normal character. So for example if normally $ is an operator or wildcard or whatever I can just write '%' and then it's a harmless dollar sign without any function and can be used normally without any conflicts.

So for example in this app here I wanted to add a rule like this:


replace following
*[??]*
with
*(??)*

But since [ acts as a wildcard it doesn't work of course. So I tried a lot of random characters and searched the forums but didn't find any solution how I can force the [ and ] to be seen as a normal character instead a wildcard even when wildcards are activated.

Sorry if my question is strangely written, english isn't my native tongue.


Oh and maybe another question that is related:

When I have a filename with this structure (without the " of course):
"AAAAAA 00 [00] AAAAAA [00]"
and I want to replace only the latter suqare brackets, and want to replace only them with round brackets. Is that possible? with just one rule without doing everything manually?

Last edited by Dokkaebi (2022-11-04 09:12)

Offline

#2 2022-11-04 10:43

Dokkaebi
Member
Registered: 2022-11-04
Posts: 3

Re: Is there a way to disable the wildcard function for the brackets?

Nevermind. I combined 3+ Filters and then I do not have to use the wildcard checkbox and everything works like a charme.
My idea to use one filter only was the problem in my thinking.

Last edited by Dokkaebi (2022-11-04 10:44)

Offline

#3 2022-11-06 00:04

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Is there a way to disable the wildcard function for the brackets?

With regular expressions this should be no problem ...

  • instead of simple wildcard you could specify the patterns more detailed

  • to catch special characters you could escape them with a prepended '\'

  • to find any character you use '.'

  • to find a character that is from a subset you use '[abc123]'

  • to find a character that is not from a subset you use '[^abc123]'

  • to find any number (even zero) of any character you use '.*'

  • for the bracketed text you could use '\[.*\]' but this will start at the first '[' and end at the last ']'

  • without any ']' inside this could be used '\[[^]]*\]'

  • to catch a block you use round brackets '(abc)' and to use it for replacement you specify the number of this pair. Here there is only one pair - so the replacment is specified by '$1'

  • for the replacement '(' and ')' don't have a special meaning. So than can be specified plain or with a backslash: '\('

  • to replace all [] by ():

    \[([^]]*)\]
    ($1)
  • if you want to replace only the last pair you have to make your pattern at the end:

    1. attach the pattern to the beginning by '^'. With '.*' you catch as much as you can. If this was to much regexp reduces this match until the next part also fits. So '^.*\[' will match the whole beginning upto the last '['. You dont' want to loose the so it has to be catched with '()' and put
      into the replacement with '$1':

      ^(.*)\[([^]]*)\]
      $1($2)
    2. attach the pattern to the end by '$'. From the last ']' to the end there shall be no more '[' specified by '[^[]*':

      \[([^]]*)\]([^[]*)$
      ($1)$2

Offline

#4 2022-11-07 06:05

Dokkaebi
Member
Registered: 2022-11-04
Posts: 3

Re: Is there a way to disable the wildcard function for the brackets?

I had to read it a couple of times to understand it, since it felt a bit overwhelming at first. But it works perfectly and I can see how useful those regular expressions can be. Thanks for your explanation of this. With the colors it's easy to remember for later which is a operator and which is a non-operating character.

\(([^)]*)\)
[$1]

\[([^]]*)\]
($1)

If I wanted to replace the first round brackets with square brackets I came up with this:

\(([^)]*)\)(.*)$
[$1]$2

Or the first square brackets with round ones:

\[([^]]*)\](.*)$
($1)$2

Last edited by Dokkaebi (2022-11-07 08:26)

Offline

#5 2022-11-07 21:29

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Is there a way to disable the wildcard function for the brackets?

Yes I tried to set it up step by step wink

As you mention the coloring. I site I like to check regular expression and to share solutions is regex101. After saving a setup you get a link to share.

So if you look at https://regex101.com/r/Nx4H1t/1 you can see the drill down on the expression to exchange all [] with ().

What you did on you attempt to change only the first pair is that you also grabbed the rest of the string. So you had to reinsert it with $2.

Unfortunatly ReNamer has no checkbox for "only one" so you have to anchor your pattern at some point. Normally you'll choose the beginning or the end (as you did).

As you could see you solution is somewhat invers to one of my proposals for changing the last: ^(.*)\[([^]]*)\]
So the other one could also be inversed from \[([^]]*)\]([^[]*)$ to ^([^[]*)\[([^]]*)\] which could be simplified:

  1. [^[]* will take all non opening brackets. .* would ignore this limitation but start chewing the whole string ...

  2. this is called greedy and could be switched off by adding a ? to the variable part (i.e. the *)

  3. you could also switch of the greediness for the whole pattern by starting it with (?-g) cool

So in short: ^(.*?)\[([^]]*)\] would also do.

Offline

#6 2022-11-07 21:33

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Is there a way to disable the wildcard function for the brackets?

Btw: multiple replacements will start to seek the next match behind the last match (and replacement). By binding your pattern to the beginning or the end the second match will never occur.

Offline

Board footer

Powered by FluxBB