Replace a string, except if the string is preceded and followed by "x"

Hi,
I want to create an action to replace a hyphen with a round bracket this is possible if i use a Format Value action $regexp(%title%, - , '('), but i also want to exclude the occasions where there is a digit before and after the hyphen \d - \d.
How will i accomplish that?

Thanks.

You want to have one regular expression looking for a hyphen excluding the case
\d space hyphen space \d
Correct?

Then you could create a regular expression loooking for
\D space hyphen space \D

The uppercase \D is a "non-digit". To be sure if this works, you should show us some real world examples.

You could try ....
Edit: the first was rubbish.

Edit 2:
This one looks better:
$regexp(%title%,(.*)[^0-9] - [^0-9](.*),'$1' '(''$2')
transforms
"Story of 6 - 6 Life" ->
"Story of 6 - 6 (Life"

Hi @LyricsLover

Real example.

Give It To Me - Vocal Club Edit (95 - 122 Transition) and i want this to be renamed to Give It To Me (Vocal Club Edit (95 - 122 Transition)

If i use the $regexp(%title%, - , '('), the result is Give It To Me (Vocal Club Edit (95 (122 Transition)

PS. there is already an action to add the the missing round bracket at the end of the (Vocal Club Edit)

If i use $regexp(%title%,\D - \D, '(',) then, the result is Give It To M (ocal Club Edit (95 - 122 Transition)

@ohrenkino if i use your regex, title remains the same as before.

Nope, this is not correct.

If i apply this one, then happens the opposite of what i want.

Give It To Me - Vocal Club Edit (95 (122 Transition)

If it is always the second hyphen that is to be left alone, then try:
$regexp('Give It To Me - Vocal Club Edit (95 - 122 Transition)',(.*?) - (.*),'$1' '(''$2')

This one works but i want to be sure that even if the \d - \d string is the first one will remain intact.

I know i could use a filter like TITLE MATCHES " - " AND NOT TITLE MATCHES "\d - \d" but i was wondering if there is a regular expression which would do the same.

then the best way is still to filter for the files that should be treated.

1 Like

I see.
I was typing almost the same :sweat_smile:.

Thanks both of you @ohrenkino and @LyricsLover for the help.

You could try it with
$regexp(%title%,(\D) - (\D),'$1 ($2'))
for your given example.

This would transform the content in %TITLE% from
Give It To Me - Vocal Club Edit (95 - 122 Transition)
into
Give It To Me (Vocal Club Edit (95 - 122 Transition))

Please test it carefully with some more real world examples.

Short explanation:
Search for a combination of
any non-digit character (and put it into the captured group $1)
followed by a space a hyphen a space
followed by any non-digit character (and put it into the captured group $2)
Then rearrange found combinations with the
content of $1 followed by a space an opening round bracket and the
content of $2
then add a closing round bracket at the end

1 Like

Hey @LyricsLover i totally missed this one.
I gave it some tries and it works, but i had to remove the last round bracket because otherwise i had a bracket at the end of every title, even those without any bracket at all.

The one that works for me is $regexp(%title%,(\D) - (\D),'$1 ($2')
if i use this one, the title will transform to Give It To Me (Vocal Club Edit (95 - 122 Transition)
afterwards i use another regular expression to close any open bracket if there is any.
Then the title will be transformed to Give It To Me (Vocal Club Edit) (95 - 122 Transition)

Thanks a lot for the help.
Appreciate it.

1 Like