# Help with replace - put word in square brackets

**URL:** https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960
**Category:** Support
**Created:** [September 17, 2024, 2:08pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960 "2024-09-17T14:08:48Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![reketekui](https://community.mp3tag.de/user_avatar/community.mp3tag.de/reketekui/32/17901_2.png) [@reketekui](https://community.mp3tag.de/u/reketekui)
#### Post date: [September 17, 2024, 2:08pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/1 "2024-09-17T14:08:48Z")

</div>

Hi all, i need to do this simple replacement of field, but i can't find how to do it:

Sample of two songs:

Original title song 1 " Macarena - Energy 5 "  
Original title song 2 " One - Energy 3"

What i need, put between brackets "Energy x"

Replaced title song 1 " Macarena - [Energy 5]  
Replaced title song 2 " One - [Energy 3]"

Until now i was replacing "Energy 3" for "[Energy 3]" but i have 7k songs, i need to automate the proccess.

Thanks in advance!!

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [September 17, 2024, 2:23pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/2 "2024-09-17T14:23:45Z")

</div>

You could use Convert Tag -\> Tag with  
Field:  
`TITLE`  
Format string:  
`$regexp(%TITLE%,(Energy \d+),'\[$1\]')`

![image](https://community.mp3tag.de/uploads/default/original/3X/0/1/016aed3bd6d097eaa03e3191a1d873c2e6b0afcf.png)

or use an Action from Type "Replace with regular expression"

The above regular expression searches for the word _Energy_ followed by a number.  
If found, it put square brackets around this found word and number.

---

<div class="post-metadata">

### Author: ![reketekui](https://community.mp3tag.de/user_avatar/community.mp3tag.de/reketekui/32/17901_2.png) [@reketekui](https://community.mp3tag.de/u/reketekui)
#### Post date: [September 17, 2024, 2:27pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/3 "2024-09-17T14:27:02Z")

</div>

Thank you so much, works like a charm.

may you tell me how to must config the action "replace with regex"? this way the config was saved as an action.

Thanks again

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [September 17, 2024, 2:28pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/4 "2024-09-17T14:28:43Z")

</div>

> [@reketekui](#):
>
> may you tell me how to must config the action "replace with regex"? this way the config was saved as an action.

![image](https://community.mp3tag.de/uploads/default/original/3X/5/a/5a601728c234306256c8a35620947afbb724cf9e.png)

Documentation about [Replace with regular expression](https://docs.mp3tag.de/actions/replace-regexp/)

The advantage of Convert Tag -\> Tag is the immediate preview and the complete preview (if you press the Preview button).

---

<div class="post-metadata">

### Author: ![reketekui](https://community.mp3tag.de/user_avatar/community.mp3tag.de/reketekui/32/17901_2.png) [@reketekui](https://community.mp3tag.de/u/reketekui)
#### Post date: [September 17, 2024, 2:42pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/5 "2024-09-17T14:42:20Z")

</div>

Sorry, this is my last question i swear xD.

Now with the action works too, but if the original title have Brackets, this action add another.  
Sample

Original: [Energy 2]  
after action: [[Energy 2]]  
Can i make a "only add brackets when there isn't?  
thanks again

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [September 17, 2024, 2:57pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/6 "2024-09-17T14:57:17Z")

</div>

Not that easy... 😉 \*\*

Just filter first for titles which contains _Energy_ without square brackets.  
Press F3 to activate the filter and enter something like  
`NOT %TITLE% HAS [Energy AND %TITLE% HAS Energy`  
Then only use your Action to this filtered list of titles with _Energy_.

\*\*  
Please be aware that there are many combinations of _Energy followed by a number_ that could occur:  
+ with leading space  
+ with any other leading character  
+ without any character like _MaximalEnergy 7_  
+ with trailing space  
+ with any other trailing characters

You should carefully check if the above regular expression matches ALL your cases.  
A previously applied filter highly reduce the risk to change TITLE content in a unwanted way.

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [September 18, 2024, 2:49pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/7 "2024-09-18T14:49:39Z")

</div>

I mean he could adjust it like this:  
 ![grafik](https://community.mp3tag.de/uploads/default/original/3X/4/0/407a96ad8f455b8b34f824964af7a0e0fbdb7ca7.png)

```auto
(Energy \d+)(?!\])

```

to only match when Energy number is not directly followed by a closing square bracket. However as you said, there are many possible cases and filtering should happen as well.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [September 18, 2024, 3:03pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/8 "2024-09-18T15:03:48Z")

</div>

> [@Casual\_Tea](#):
>
> `(Energy \d+)(?!\])`

Yes, a search with a "negative lookahead" would be possible:

 ![image](https://community.mp3tag.de/uploads/default/original/3X/7/b/7b5b92bf50300960d47d957a07b4d0c4b4f97d45.png)

The more the OP wants this regular expression to be automated and reusable, the more strictly it must be specified.

---

<div class="post-metadata">

### Author: ![lkantrov](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/edb3f5/32.png) [@lkantrov](https://community.mp3tag.de/u/lkantrov)
#### Post date: [September 19, 2024, 4:43am UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/9 "2024-09-19T04:43:47Z")

</div>

Sometimes when I run into this type of situation instead of trying to write a more complicated regex/action to perfectly do what I want, I just create another action in the action group to fix the imperfect "fix". 🙂

So in your example, instead of trying to arrive at an action that only add brackets when necessary, I'd add an action to clean up the double brackets by replacing the double brackets with single ones.

---

<div class="post-metadata">

### Author: ![lkantrov](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/edb3f5/32.png) [@lkantrov](https://community.mp3tag.de/u/lkantrov)
#### Post date: [September 19, 2024, 4:44am UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/10 "2024-09-19T04:44:41Z")

</div>

Here's an example of the actions you could add to the end of your original action group.

![DS041](https://community.mp3tag.de/uploads/default/original/3X/1/a/1aef2d1d712b7fbac43b71df119e90c680db59ca.png)

This has the benefit of being easy to understand and debug later as compared with a more complex regex that often are nearly unreadable unless you're a software programmer by day.

Hope that helps.

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [September 19, 2024, 1:21pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/11 "2024-09-19T13:21:05Z")

</div>

I initially thought up a regex that does something like that.

```auto
\[?(Energy \d+)\]?

```

matches Energy + optionally brackets around it.

My reasoning for not going that route is pointless computation (and yes, I do write programs/scripts so maybe I'm biased).  
This regex "changes" the value of all instances of [Energy number] to the same data as it was before, which is a needless step.

With the negative lookahead of my regex, the computation stops when a "]" is found after "Energy number".  
With how fast computers are these days it's likely irrelevant but I like to create clean and efficient solutions.

If you don't understand a regex, copy it into Chat GPT or another AI of your choice and it will in most cases explain to you very well how and why they work.

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [October 19, 2024, 1:21pm UTC](https://community.mp3tag.de/t/help-with-replace-put-word-in-square-brackets/65960/12 "2024-10-19T13:21:08Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
