# Only one %catalognumber%

**URL:** https://community.metabrainz.org/t/only-one-catalognumber/430477
**Category:** MusicBrainz Picard
**Tags:** filenaming
**Created:** [June 2, 2019, 4:30pm UTC](https://community.metabrainz.org/t/only-one-catalognumber/430477 "2019-06-02T16:30:25Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![Harakku](https://community.metabrainz.org/user_avatar/community.metabrainz.org/harakku/32/23727_2.png) [@Harakku](https://community.metabrainz.org/u/Harakku)
#### Post date: [June 8, 2019, 9:00pm UTC](https://community.metabrainz.org/t/only-one-catalognumber/430477/3 "2019-06-08T21:00:03Z")

</div>

You can use the regex search to choose only the first value before a multi-value separator (the default is `"; "`).

```taggerscript
$if(%catalognumber%,[$rsearch(%catalognumber%,\(.+?\)\(?:; |\$\))])

```

Here’s the plain regex without escape characters ([and the same on regex101.com](https://regex101.com/r/01ESC5/2))

```auto
(.+?)(?:; |$)

```

This solution isn’t 100% perfect because if a catalog number itself includes the separator, the value gets split up like if it was two values: `"c4t4; l0gnumb3r"` would give us `"c4t4"` instead of the whole value.

The above restriction seems unavoidable with the default functions. _I just happened to make a plugin_ which gets past the mentioned restriction but in practice, the regex method works almost as well. [[.](https://community.metabrainz.org/t/first-level-second-level-third-level-create/431089/8)]

```python
PLUGIN_NAME = "Get Multi-value Subset"
PLUGIN_AUTHOR = "Joel Lintunen"
PLUGIN_DESCRIPTION = """Returns a subset of values from a multi-value tag.
<br /><br />
Examples:
<ul>
  <li><i>$getmultirange(catalognumber,0)</i> returns the first value if it exists</li>
  <li><i>$getmultirange(writer,2:4,\, )</i> returns the third and fourth values if they exist, separated by a
      comma</li>
</ul>
Arguments:
<ol>
  <li>Multi-value tag.</li>
  <li>List index or slicer. For example <i>"0"</i>, <i>":2"</i>, <i>"::2"</i> or <i>"-1"</i>.</li>
  <li>Separator which will be used to divide the values. The default is <i>"; "</i>.</li>
</ol>
"""
PLUGIN_VERSION = "1.0.0"
PLUGIN_API_VERSIONS = ["2.0", "2.1", "2.2"]
PLUGIN_LICENSE = "GPL-2.0"
PLUGIN_LICENSE_URL = "https://www.gnu.org/licenses/gpl-2.0.html"

from picard.metadata import MULTI_VALUED_JOINER
from picard.script import (
    normalize_tagname,
    register_script_function)

def func_get_multi_range(parser, multi, range, separator=MULTI_VALUED_JOINER):
    # Check inputs to prevent crashes on the options page
    if not multi or not range or not all(x.isdigit() or x in [':', '-', '+'] for x in range):
        return ""

    multi_values = parser.context.getall(normalize_tagname(multi))
    try:
        # Check if range is an index instead of a slicer
        if len(range.split(':')) == 1:
                return multi_values[int(range)]
        return separator.join(eval("{0}[{1}]".format(multi_values, range)))
    except (IndexError, SyntaxError, ValueError):
        return ""

register_script_function(func_get_multi_range, "getmultirange")

```

---

_[View the full topic](https://community.metabrainz.org/t/only-one-catalognumber/430477)._
