# Replace " / " with ", " except when there is only one " / " or it is the last " / ", then replace with " & "

**URL:** <https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479>\
**Category:** Support\
**Created:** [February 24, 2022, 9:18pm UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479 "2022-02-24T21:18:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)\
**Post date:** [February 24, 2022, 9:18pm UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479/1 "2022-02-24T21:18:56Z")

</div>

Hello,

I have been working with this script that I amalgamated from other scrips garnered here and I would like to get the second to last portion of this action to replace " / " with ", " except when there is only one " / " or it is the last " / ". If then, replace with " & "

Can anyone help me figure out how to do this?

[Last Name, First Name More to First Name Last Name (Not affected by Forward slash), replace with , Artist; Artist to Involved People; Album Artist to Artist Sort.mta](https://community.mp3tag.de/uploads/short-url/sHfJUjk4BYhD7No0EW9LB2vh3YZ.mta) (449 Bytes)

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [February 24, 2022, 9:30pm UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479/2 "2022-02-24T21:30:41Z")

</div>

I don't know what you really want to achieve with the action group that you offered ...  
But if you first split the ARTIST field with the / as separator and then you remove all duplicate fields of the type ARTIST then you will never get the / as part of the field ARTIST, I would say.

From a plausibility point of view ..  
you want to have artists like artist1, artist2 / artist3 & artist4?  
instead of artist1, artist2, artist3 & artist4

---

<div class="post-metadata">

**Author:** ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)\
**Post date:** [February 24, 2022, 11:06pm UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479/3 "2022-02-24T23:06:31Z")

</div>

Hello ohrenkino,

Sorry for not being clear.

I had set up some fields (sometimes it was the artist field and other times the artist sort field, an inconsistency I am trying to clean up) to list all the performers separated by " / ". So I would have:

Thea King / Gabrieli String Quartet / Kenneth Sillito / Brendan O'reilly / Ian Jewel / Keith Harvey

I want to copy this information to the involved people but then I need to convert the artist (sometimes artist sort field but I can change the script later to address that field) to read:

Thea King, Gabrieli String Quartet, Kenneth Sillito, Brendan O'reilly, Ian Jewel & Keith Harvey

However, some times I just have just two entities listed:

Andras Schiff / New Vienna Octet

and I would like it to read:

Andras Schiff & New Vienna Octet

Basically the last, or only " / " should be converted to " & "

Hopefully I have presented the state of affairs clearly. Thanks for your attention to this, it is appreciated!

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [February 25, 2022, 6:28am UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479/4 "2022-02-25T06:28:47Z")

</div>

Then try the following:  
First (simple) replace all slashes / with a comma.  
Then try the following "Replace with regular expression":  
Search string: `(.*), (.*)`  
Replace with: `$1 & $2`

The greadiness will take care that this always happens only to the last comma.

---

<div class="post-metadata">

**Author:** ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)\
**Post date:** [February 25, 2022, 3:16pm UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479/5 "2022-02-25T15:16:01Z")

</div>

> [@ohrenkino](#):
>
> $1 & $2

Perfect!

> [@ohrenkino](#):
>
> The greadiness will take care that this always happens only to the last comma.

Not sure how the greediness does it, but I am glad it does!

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [February 25, 2022, 3:17pm UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479/6 "2022-02-25T15:17:42Z")

</div>

😉  
I picked that up from the help:

> **[Replace with Regular Expression – Mp3tag Documentation](https://docs.mp3tag.de/actions/replace-regexp/)**
>
> Documentation on the Replace with Regular Expression action type that can be performed as Quick Action or as reusable workflow from Action Groups. Mp3tag is the universal Tag Editor.

where it talks about non-greedy repeats ...

---

<div class="post-metadata">

**Author:** ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)\
**Post date:** [February 25, 2022, 3:19pm UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479/7 "2022-02-25T15:19:19Z")

</div>

Thanks for the link. I know I have read this before but this stuff just leaks out of my mind if I don't use it regularly. I will re-read and hopefully it will someday stick.

....actually, I read it, or at least the part about non-greedy repeats. Still can't find the greedy explanation...

---

<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:** [February 25, 2022, 3:40pm UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479/8 "2022-02-25T15:40:06Z")

</div>

> [@esumsea](#):
>
> Still can't find the greedy explanation...

> The standard quantifiers in regular expressions are **greedy** , meaning they match as much as they can, only giving back as necessary to match the remainder of the regex.
> 
> By using a **lazy** quantifier, the expression tries the minimal match first.

And for a long detailed explanation, you could [read here](https://www.rexegg.com/regex-quantifiers.html) for example.

---

<div class="post-metadata">

**Author:** ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)\
**Post date:** [February 25, 2022, 3:47pm UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479/9 "2022-02-25T15:47:35Z")

</div>

Thanks LyricsLover, especially for the detailed link, which I have bookmarked. I am going to read that 100 times and let it digest. 😊

Maybe if I took as much time learning scripting as I do music tagging I would be proficient, but alas, it is not a strong point of mine. That is why I so appreciate this community and the help of people like you, ohrenkino and Florian.

It is a very generous and kind and I really do appreciate it in this world where such qualities seem to be evaporating.

---

<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:** [March 27, 2022, 3:48pm UTC](https://community.mp3tag.de/t/replace-with-except-when-there-is-only-one-or-it-is-the-last-then-replace-with/56479/10 "2022-03-27T15:48:33Z")

</div>

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