Renaming - Different output based on the match

I have a situation like this
(MATCH1)(.*)(MATCH2)

Sometimes I have something in \2 and sometimes not.
I want to output -\2- only if there is something in it (it becomes likes -aaa-) and if not, I don't want an output like this --
Is this possible with REGEX or should I go for more complicated scripts?
Are there condition matching in the output in REGEX?

You almost had it.
Yes, use a regular expression.

Old Name is (MATCH1)(.+)(MATCH2)
New Name is \1-\2-\3

Perhaps this is better ?
Old Name is "(MATCH1)(.+)(MATCH2)(...)"
New Name is "\1-\2-\3\4"

Or in a button:

rename regexp PATTERN="(MATCH1)(.+)(MATCH2)(.*\..*)" TO="\1-\2-\3\4"

The + operator does not match unless there is at least one character between the two MATCHES. :slight_smile:

That doesn't work what you gave. Imagine this
(MATCH1)(MATCH2)
Your output gives:
MATCH1--MATCH2

As I said I don't want an output of -- if \2 is empty.

Oh and the match has to be (.*)
Sometimes there is something there and sometimes not.

OK, something is wrong.
My code works here. Perhaps I misunderstand the problem.
I think it is best to wait. There may be a better reply to this problem soon.

Here is an example

Match1aaaMatch2Match3 should give
Match1-aaa-Match2[Match3]

Match1Match2Match3 should give
Match1Match2[Match3]

So I still need to manipulate the output even if \2 is empty. If \2 is empty, it does not mean that my work is finished.

I don't know a way to do that using just regular expressions.

If you want conditional logic it's probably best to use a rename script.