# Example: How to sorting field with Label and separator : commas, semicolon, double slash \`\\\\\`

**URL:** https://community.mp3tag.de/t/example-how-to-sorting-field-with-label-and-separator-commas-semicolon-double-slash/71886
**Category:** General Discussion
**Created:** [September 26, 2026, 3:04pm UTC](https://community.mp3tag.de/t/example-how-to-sorting-field-with-label-and-separator-commas-semicolon-double-slash/71886 "2026-09-26T15:04:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![juvalu](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@juvalu](https://community.mp3tag.de/u/juvalu)
#### Post date: [September 26, 2026, 3:04pm UTC](https://community.mp3tag.de/t/example-how-to-sorting-field-with-label-and-separator-commas-semicolon-double-slash/71886/1 "2026-09-26T15:04:28Z")

</div>

## Sorting Composer Fields with Labels and Separators

This document provides ready-to-use Mp3tag formatting actions for sorting fields that contain labels (for example `Composed:`, `Music:`, `Lyrics:`, `Written:`) and different separators such as commas, semicolons, and true multi-value `\\` separators.

The formulas below have been tested with **Convert \> Tag - Tag** and/or **Format value** actions.

> **Important**  
> Always test on copies or backed-up files first. Some formulas intentionally convert between a true multi-value field and a single text value.

* * *

### 1. Sorting a Single Field with Label and Commas

#### Input

> Composed: Kasa Allah, Benny Golson, Stuart Gorrell, Hoagy Carmichael

#### Output

> Composed: Benny Golson, Hoagy Carmichael, Kasa Allah, Stuart Gorrell

#### Without label

For a true **single-value text field** whose items are separated by commas:

```plaintext
$sort(%composer%,', ')

```

#### With label `Composed:`

```plaintext
Composed: $sort($regexp(%composer%,^Composed:\s*,),', ')

```

#### Logic Flow

- `%composer%` → reads the single text value.
- `$regexp(...,^Composed:\s*,,)` → removes the initial `Composed:` label and any following spaces.
- `$sort(...,', ')` → sorts the comma-separated names alphabetically.
- `Composed: ` → is added back once at the beginning.

> The older form `$sort($meta_sep(composer,),', ')` can also work when `COMPOSER` contains only one physical value, but `%composer%` is clearer here because this section concerns a single-value field.

* * *

### 2. Multi-Value Field Variant (`\\` separator)

#### Example input

```plaintext
Composed: Kasa Allah\\Benny Golson\\Stuart Gorrell\\Hoagy Carmichael

```

#### Action

```plaintext
Composed: $sort($replace($meta_sep(composer,\\),Composed: ,),'\\')

```

#### Output

```plaintext
Composed: Benny Golson\\Hoagy Carmichael\\Kasa Allah\\Stuart Gorrell

```

#### Logic Flow

- `$meta_sep(composer,\\)` → collects all values of the multi-value `COMPOSER` field using `\\` as the working separator.
- `$replace(...,Composed: ,)` → removes `Composed: `.
- `$sort(...,'\\')` → sorts the values alphabetically using `\\` as the delimiter.
- `Composed: ` → is re-added once at the beginning.

#### Assumption

This formula assumes that `Composed: ` appears only as the initial label and is not part of a person's name or another value.

* * *

### 3. Case-Insensitive Label Variants

Mp3tag's fourth `$regexp()` parameter can enable case-insensitive matching:

```plaintext
$regexp(text,expression,replacement,1)

```

The final `1` means that the regular-expression match ignores capitalization.

Therefore the same expression can match:

```plaintext
Composed:
composed:
COMPOSED:
CoMpOsEd:

```

#### Single field — commas

```plaintext
Composed: $sort($regexp(%composer%,^composed:\s*,,1),', ')

```

#### Multi-value — `\\`

```plaintext
Composed: $replace($sort($regexp($meta_sep(composer,|),^composed:\s*,,1),'|'),|,\\)

```

#### Logic Flow for the multi-value version

```plaintext
$meta_sep(composer,|)
        ↓
Temporarily joins all values with |

$regexp(...,^composed:\s*,,1)
        ↓
Removes the label regardless of capitalization

$sort(...,'|')
        ↓
Sorts the values

$replace(...,|,\\)
        ↓
Restores the true multi-value separator

```

> **Temporary separator rule**  
> The character `|` is used only as a safe temporary delimiter. Use it only when `|` does not occur in the actual tag data.

* * *

### 4. Semicolon Separator Variants

#### Single field already separated by `; `

If the field is a **single text value** whose names are separated by semicolons:

```plaintext
Composed: $sort($regexp(%composer%,^composed:\s*,,1),'; ')

```

Example:

```plaintext
Composed: Kasa Allah; Benny Golson; Stuart Gorrell; Hoagy Carmichael

```

becomes:

```plaintext
Composed: Benny Golson; Hoagy Carmichael; Kasa Allah; Stuart Gorrell

```

#### Convert multi-value `\\` input to a single semicolon-separated value

```plaintext
Composed: $replace($sort($regexp($meta_sep(composer,|),^composed:\s*,,1),'|'),|,'; ')

```

This formula intentionally converts:

```plaintext
A\\B\\C

```

into:

```plaintext
A; B; C

```

So the result is **no longer a true Mp3tag multi-value field**. It is one text value containing semicolon-separated items.

* * *

### 5. Sorting Multi-Value `COMPOSER` with Two Fixed Labels (`Music` / `Lyrics`)

This version is positional.

It works only when:

- exactly two `COMPOSER` values are expected;
- value `0` is always `Music:`;
- value `1` is always `Lyrics:`.

#### Input

```plaintext
Music: Tommaso Demuro, Steve Swallow, David Pritchard\\Lyrics: Gary Burton, Bill Goodwin, Apple Green

```

#### Output

```plaintext
Music: David Pritchard, Steve Swallow, Tommaso Demuro\\Lyrics: Apple Green, Bill Goodwin, Gary Burton

```

#### Action

```plaintext
Music: $sort($regexp($meta(composer,0),^music:\s*,,1),', ')\\Lyrics: $sort($regexp($meta(composer,1),^lyrics:\s*,,1),', ')

```

#### Logic Flow

- `$meta(composer,0)` → reads the first physical `COMPOSER` value, assumed to be the Music block.
- `$regexp(...,^music:\s*,,1)` → removes `Music:` case-insensitively.
- `$sort(...,', ')` → sorts the names inside the Music block.
- `Music: ` → is added back before that sorted block.

Then:

- `$meta(composer,1)` → reads the second physical `COMPOSER` value, assumed to be the Lyrics block.
- `$regexp(...,^lyrics:\s*,,1)` → removes `Lyrics:` case-insensitively.
- `$sort(...,', ')` → sorts the names inside the Lyrics block.
- `Lyrics: ` → is added back before that sorted block.
- `\\` → keeps the two values physically separate as a true multi-value field.
- `,1` → enables case-insensitive matching in each `$regexp()`.

> `$meta(composer,0)` and `$meta(composer,1)` select values by **position** , not by label content.

* * *

### 6. Sorting Music/Lyrics When Their Positions Are Not Fixed

This version solves two tasks at the same time:

1. it normalizes the label order to the fixed canonical order **Music → Lyrics** ;
2. it sorts the names alphabetically inside each label;
3. label recognition is case-insensitive;
4. it works whether the input is `Music\\Lyrics` or `Lyrics\\Music`.

#### Assumptions

- exactly two `COMPOSER` values are expected;
- one begins with `Music:`;
- the other begins with `Lyrics:`;
- the label starts at the first character of each value.

#### Action

```plaintext
$if($eql($left($meta(composer,0),6),Music:),Music: $sort($regexp($meta(composer,0),^music:\s*,,1),', ')\\Lyrics: $sort($regexp($meta(composer,1),^lyrics:\s*,,1),', '),Music: $sort($regexp($meta(composer,1),^music:\s*,,1),', ')\\Lyrics: $sort($regexp($meta(composer,0),^lyrics:\s*,,1),', '))

```

#### Logic Flow

```plaintext
$left($meta(composer,0),6)

```

reads the first six characters of value `0`.

Then:

```plaintext
$eql(...,Music:)

```

asks whether the first value begins with `Music:`.

If **YES** :

```plaintext
meta 0 → Music
meta 1 → Lyrics

```

If **NO** :

```plaintext
meta 1 → Music
meta 0 → Lyrics

```

In both cases the field is reconstructed as:

```plaintext
Music: ...\\Lyrics: ...

```

Therefore the formula is **normalizing** , not simply positional.

#### Example A — original order

```plaintext
Music: Tommaso Demuro, Steve Swallow, David Pritchard\\Lyrics: Gary Burton, Bill Goodwin, Apple Green

```

#### Example B — swapped input

```plaintext
Lyrics: Gary Burton, Bill Goodwin, Apple Green\\Music: Tommaso Demuro, Steve Swallow, David Pritchard

```

Both produce:

```plaintext
Music: David Pritchard, Steve Swallow, Tommaso Demuro\\Lyrics: Apple Green, Bill Goodwin, Gary Burton

```

> This is a **fixed/canonical label order** , not an alphabetical label order. Alphabetically, `Lyrics` comes before `Music`.

* * *

### 7. Automatic Sorting of Two Labeled Multi-Values: Labels + Names

This version performs two independent alphabetical sorts:

1. alphabetical sorting of the names inside each label;
2. alphabetical sorting of the complete labeled blocks themselves.

It is designed for **exactly two labeled multi-values**.

#### Action

```plaintext
$replace($sort($regexp($meta(composer,0),'^([^:]+):.*','$1'): $sort($regexp($meta(composer,0),'^[^:]+:\s*',,1),', ')|$regexp($meta(composer,1),'^([^:]+):.*','$1'): $sort($regexp($meta(composer,1),'^[^:]+:\s*',,1),', '),'|'),|,\\)

```

#### What this version does

- automatically extracts each label;
- does not require the literal words `Music` or `Lyrics` in the formula;
- removes each label before sorting the associated names;
- sorts the names alphabetically;
- rebuilds each complete `Label: names` block;
- sorts the two complete blocks alphabetically by their leading label text;
- restores the true multi-value `\\` separator;
- works regardless of which labeled block is initially value `0` or value `1`;
- label extraction itself does not depend on capitalization because no specific label word is hard-coded.

#### Logic Flow

The following part:

```plaintext
$regexp($meta(composer,0),'^([^:]+):.*','$1')

```

automatically extracts everything before the first colon.

For example:

```plaintext
Music

```

or:

```plaintext
Lyrics

```

This part:

```plaintext
$regexp($meta(composer,0),'^[^:]+:\s*',,1)

```

removes the complete initial `Label:` portion, leaving only the names.

Then:

```plaintext
$sort(...,', ')

```

sorts the comma-separated names inside that block.

The same operations are performed independently on `$meta(composer,1)`.

At this stage the two reconstructed blocks are temporarily joined with `|`, for example:

```plaintext
Music: David Pritchard, Steve Swallow, Tommaso Demuro|Lyrics: Apple Green, Bill Goodwin, Gary Burton

```

Then:

```plaintext
$sort(...,'|')

```

sorts the complete blocks alphabetically according to the text at the beginning of each block:

```plaintext
Lyrics: ...
Music: ...

```

Finally:

```plaintext
$replace(...,|,\\)

```

converts the temporary delimiter back into the true Mp3tag multi-value separator.

#### Why the regex patterns are quoted

These two patterns contain square brackets:

```plaintext
'^([^:]+):.*'
'^[^:]+:\s*'

```

In Mp3tag Format Strings, `[` and `]` have their own special meaning. Wrapping these regular-expression patterns in single quotes prevents Mp3tag from interpreting the square brackets before the pattern reaches the regex engine.

#### Example 1

Input:

```plaintext
Music: Tommaso Demuro, Steve Swallow, David Pritchard\\Lyrics: Gary Burton, Bill Goodwin, Apple Green

```

Output:

```plaintext
Lyrics: Apple Green, Bill Goodwin, Gary Burton\\Music: David Pritchard, Steve Swallow, Tommaso Demuro

```

#### Example 2 — swapped input

Input:

```plaintext
Lyrics: Gary Burton, Bill Goodwin, Apple Green\\Music: Tommaso Demuro, Steve Swallow, David Pritchard

```

Output:

```plaintext
Lyrics: Apple Green, Bill Goodwin, Gary Burton\\Music: David Pritchard, Steve Swallow, Tommaso Demuro

```

#### Assumptions and limitations

- Exactly two physical `COMPOSER` values are processed because the formula explicitly references `$meta(composer,0)` and `$meta(composer,1)`.
- Each physical value must begin with a label followed by a colon, for example `Music:` or `Lyrics:`.
- The label itself must not contain an additional colon before the separator colon.
- Names inside each block are expected to be separated by `, `.
- The temporary `|` character must not occur in the original tag data.
- Sorting behavior is provided by Mp3tag's `$sort()` function; this formula does not add a separate case-sensitivity option to `$sort()`.

* * *

### 8. Function Reference Used in These Examples

#### `$sort(x,y)`

Sorts the segments in `x` using `y` as the delimiter.

Examples:

```plaintext
$sort(%composer%,', ')
$sort(...,'\\')
$sort(...,'|')

```

#### `$meta(field,n)`

Returns the `n`-th physical value of a multi-value field. Indexing starts at `0`.

```plaintext
$meta(composer,0)
$meta(composer,1)

```

#### `$meta_sep(field,separator)`

Collects all physical values of a multi-value field and joins them temporarily with the chosen separator.

```plaintext
$meta_sep(composer,\\)
$meta_sep(composer,|)

```

#### `$regexp(text,expression,replacement,1)`

Runs a regular-expression replacement. The optional fourth parameter `1` enables case-insensitive matching.

```plaintext
$regexp(%composer%,^composed:\s*,,1)

```

#### `$replace(text,search,replace)`

Performs a literal replacement and is useful when regular expressions are unnecessary.

```plaintext
$replace($meta_sep(composer,\\),Composed: ,)

```

#### `$eql(x,y)`

Compares two strings. In the formulas above it is used to detect whether value `0` begins with `Music:`.

* * *

### 9. Choosing the Correct Formula

Use the formula that matches the **real structure of the field** , not only what it looks like in Mp3tag.

| Scenario | Recommended section |
| --- | --- |
| One text value, names separated by commas | 1 |
| True multi-value field separated by `\\` | 2 |
| Label capitalization may vary | 3 |
| Single text value separated by semicolons | 4 |
| Convert true multi-values to one semicolon-separated string | 4 |
| Exactly two values, fixed `Music` then `Lyrics` positions | 5 |
| Exactly two values, `Music` / `Lyrics` positions may be swapped, but output must always be `Music → Lyrics` | 6 |
| Exactly two generic labeled values; both labels and names must be sorted alphabetically | 7 |

* * *

### Notes

- All examples are intended for **Convert \> Tag - Tag** or **Format value** actions.
- When adapting the examples to another field, replace the field consistently everywhere. For example, changing `COMPOSER` to another field may require changing `%composer%`, `$meta(composer,...)`, and `$meta_sep(composer,...)`.
- A displayed `\\` separator represents separate physical values in a true multi-value field; a comma or semicolon inside one value is only text unless the field is explicitly split into multiple values.
- Temporary separators such as `|` must not occur in the source data.
- Re-running the normalizing formulas on already normalized data should leave the logical result unchanged, provided the stated assumptions are respected.
- Always back up your files before using bulk actions.
- If you find errors or want to improve the formulas, feel free to edit this document.
- Thanks, ChatGPT, for the help.

* * *

---

<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 26, 2026, 3:29pm UTC](https://community.mp3tag.de/t/example-how-to-sorting-field-with-label-and-separator-commas-semicolon-double-slash/71886/2 "2026-09-26T15:29:52Z")

</div>

> [@juvalu](#):
>
> - Thanks, ChatGPT, for the help.

Did ChatGPT also mention that the results are currently sorted by first name?

For your example:

> Composed: Kasa Allah, Benny Golson, Stuart Gorrell, Hoagy Carmichael

I would expect the following output if sorted by last name:

> Composed: Kasa Allah, Hoagy Carmichael, Benny Golson, Stuart Gorrell

Even better, it would be great if users could choose the preferred sort order themselves.

Just as a note:  
I haven’t read through your rather lengthy post in full, and I haven’t tested this any further myself.

---

<div class="post-metadata">

### Author: ![juvalu](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@juvalu](https://community.mp3tag.de/u/juvalu)
#### Post date: [September 26, 2026, 5:29pm UTC](https://community.mp3tag.de/t/example-how-to-sorting-field-with-label-and-separator-commas-semicolon-double-slash/71886/3 "2026-09-26T17:29:25Z")

</div>

The sorting is by name. Regarding user preferences, I agree with you; my tags come from Discogs, where they are sorted by name. As for the length of the post, I simply listed variations of the scenarios, which in some cases can be adapted to other fields.
