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.
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.
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.
Here's an example of the actions you could add to the end of your original action group.
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.
I initially thought up a regex that does something like that.
\[?(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.