# Album volume to discnumber action (general method using regexp)

**URL:** <https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490>\
**Category:** Support\
**Created:** [June 30, 2020, 8:49am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490 "2020-06-30T08:49:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev91618](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dev91618](https://community.mp3tag.de/u/dev91618)\
**Post date:** [June 30, 2020, 8:49am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/1 "2020-06-30T08:49:59Z")

</div>

Hello all. Please believe me that this is after a lot of trying.  
I have several albums with names with

- 'Vol.' or 'Vol' or 'Volume' or 'vol.'
- followed with or without space or spaces,
- followed with numbers of 1-5 digits **(this is what I want to extract and turn into discnumber)**
- sometimes as the last thing, but other times with more alphanumerics after that which are to be ignored.

Examples

- XYZ Volume11
- XYZ Volume 123
- XYZ Vol.123
- XYZ Vol. 9
- XYZ Vol 88 abc
- XYZ volume1abc

I have tried several regexp strategies, some of them worked in Sublime text, but none perfectly in mp3tag action.

Specifically  
vol.\* (\d+)  
or  
(\d+)(?!.\*\d)  
look promising but do not give results when used as  
format DISCNUMBER  
$regexp(%album%, **expression** ,$1)

I would like to create action  
format DISCNUMBER  
$regexp(%album%, **expression** ,$1), if its the correct way to go about it.

I am looking for the best possible **expression** above. Any help will be immensely helpful organize my collection. As you can imagine, I am using this to merge volumes as single album.

Thanks a lot and good day.

---

<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:** [June 30, 2020, 9:18am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/2 "2020-06-30T09:18:11Z")

</div>

You could try:  
`$num($regexp(%album%,.*?(\d+),$1),1)`

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [June 30, 2020, 12:27pm UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/3 "2020-06-30T12:27:50Z")

</div>

Did you try something like `\bVol(?:\.|ume)\w*(\d+)` for the expression?

---

<div class="post-metadata">

**Author:** ![dev91618](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dev91618](https://community.mp3tag.de/u/dev91618)\
**Post date:** [June 30, 2020, 7:50pm UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/4 "2020-06-30T19:50:34Z")

</div>

Hello. Thanks a lot. This is one problem I am constantly facing. The regex expression seems great. When I test it in sublime text for example.  
But but but... when I  
create action  
Format Value  
Field: DISCNUMBER  
Format String: $regexp(%album%,\bVol(?:.|ume)\w\*(\d+),$1)

I get the entire album name (entire alphanumeric album name) as discnumber rather than just the intended volume number.

Of course I am not technically very sound and don't know what $1 means here, someone had suggested it elsewhere. I want to cry. Please help.

---

<div class="post-metadata">

**Author:** ![dev91618](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dev91618](https://community.mp3tag.de/u/dev91618)\
**Post date:** [June 30, 2020, 7:52pm UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/5 "2020-06-30T19:52:54Z")

</div>

Hello. Thanks a lot. As of initial testing, this seems to be working. I will report more. This helps a lot.

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [July 1, 2020, 5:04am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/6 "2020-07-01T05:04:28Z")

</div>

The dollar sign `$` variables refer to terms in round parentheses `()` from left to right, unless manually excluded, which is what I did with that funky `?:` in there.

Iʼm not quite sure why or whether `$num()` is really required here, but you can alter the expression within of course.

---

<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:** [July 1, 2020, 5:13am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/7 "2020-07-01T05:13:15Z")

</div>

> [@Crissov](#):
>
> why or whether `$num()`

In my expression you end up with a string starting with a number.  
This could be  
123  
for "XYZ Volume 123"  
but also  
88 abc  
for "XYZ Vol 88 abc"  
And to transform that string into a number - which means to cut everything non-numerical - I simply used the $num() function.  
But as there are many ways that lead to Rome, one probably could have done it with a nested $regexp() or something similar.

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [July 1, 2020, 5:27am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/8 "2020-07-01T05:27:16Z")

</div>

You are only matching for a string of digits with `(\d+)` anyway. That is why Iʼm confused by `$num()`.

Considering the entire album field content (with start `^` and end `$` markers) _should_ work then: `$regexp(%album%,^.*\bVol(?:.|ume)\w*(\d+).*$,$1)`.

---

<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:** [July 1, 2020, 5:31am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/9 "2020-07-01T05:31:42Z")

</div>

> [@Crissov](#):
>
> `$regexp(%album%,^.*\bVol(?:.|ume)\w*(\d+).*$,$1)` .

This does not work for "XYZ Volume 123" as nothing follows the number.

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [July 1, 2020, 6:58am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/10 "2020-07-01T06:58:36Z")

</div>

`.*$` matches anything at the end, including nothing.

---

<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:** [July 1, 2020, 7:06am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/11 "2020-07-01T07:06:23Z")

</div>

Before we start a theoretical discussion - this is what the preview in Convert\>Tag-Tag shows:  
 ![Screenshot](https://community.mp3tag.de/uploads/default/original/2X/e/e97151727ddc916114f1a03c8529dccf81e02c89.png)

![Screenshot_2](https://community.mp3tag.de/uploads/default/original/2X/d/d1be13f33f97da303d51128002805905f30c353e.png)

![Screenshot_3](https://community.mp3tag.de/uploads/default/original/2X/3/3381321e25c4f68de5f245dfa401767c17dd4f13.png)

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [July 1, 2020, 7:27am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/12 "2020-07-01T07:27:05Z")

</div>

You are right, I screwed up: I mixed up `\w` (_ **w** ord character_) with either `\W` (its inverse) or `\s` (_white **s** pace character_). My bad.  
(For a moment, I was afraid those predefined character classes were not [supported in Mp3tag](https://docs.mp3tag.de/actions/replace-regexp), but they are.)

I tested the following scripts successfully with all example strings in this thread:

- `$regexp(%album%,^.*\bVol(?:\.|ume)\s*(\d+).*$,$1)`
- `$regexp(%album%,^.*\bVol(?:\.|ume)\W*(\d+).*$,$1)`

---

<div class="post-metadata">

**Author:** ![dev91618](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dev91618](https://community.mp3tag.de/u/dev91618)\
**Post date:** [July 5, 2020, 1:32pm UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/13 "2020-07-05T13:32:46Z")

</div>

Hello. Thanks. But this does not work for album names such as  
abc vol. 15 live on date 13/12/1990  
It gives output of disc number as 1513121990 and some how $cutright applie don top does not work either.  
Thanks for any further advice.

---

<div class="post-metadata">

**Author:** ![dev91618](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dev91618](https://community.mp3tag.de/u/dev91618)\
**Post date:** [July 5, 2020, 1:36pm UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/14 "2020-07-05T13:36:49Z")

</div>

Hello. This seems to be working wonderfully, though a bit slow (too much computing going on there). But its amazing. I will test further and report back. Thanks everyone.

---

<div class="post-metadata">

**Author:** ![dev91618](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dev91618](https://community.mp3tag.de/u/dev91618)\
**Post date:** [July 6, 2020, 7:59pm UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/15 "2020-07-06T19:59:38Z")

</div>

Hello there, thanks a lot. I have been using the version  
$regexp(%album%,^._\bVol(?:.|ume)\s_(\d+).\*$,$1)  
But its failing when (Vol1) is in brackets.  
Thanks for the amazing help. Some more improvements in this regard will be highly appreciated, even though 90% of my problem is already solved by you.  
Cheers.

> [@Crissov](#):
>
> $regexp(%album%,^._\bVol(?:.|ume)\s_(\d+).\*$,$1)

---

<div class="post-metadata">

**Author:** ![dev91618](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dev91618](https://community.mp3tag.de/u/dev91618)\
**Post date:** [July 7, 2020, 11:30pm UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/16 "2020-07-07T23:30:00Z")

</div>

Hello there.

This is great, but does not work for situations  
(Vol 5)  
Vol 5,  
Vol 5:

I mean when volume the number to be fetched is immediately followed by ) , :

Any further guidance will go a long way.

Thanks.

> [@Crissov](#):
>
> - `$regexp(%album%,^.*\bVol(?:\.|ume)\s*(\d+).*$,$1)`
> - `$regexp(%album%,^.*\bVol(?:\.|ume)\W*(\d+).*$,$1)`

---

<div class="post-metadata">

**Author:** ![dev91618](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dev91618](https://community.mp3tag.de/u/dev91618)\
**Post date:** [July 7, 2020, 11:59pm UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/18 "2020-07-07T23:59:25Z")

</div>

I don't know what changed, but this stopped working altogether. It was working yesterday.

![image](https://community.mp3tag.de/uploads/default/original/2X/5/53d7b6d8d5f6b439e9fb6be755a4e34861cf8a92.png)

> [@Crissov](#):
>
> $regexp(%album%,^._\bVol(?:.|ume)\W_(\d+).\*$,$1)

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [July 8, 2020, 4:53am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/19 "2020-07-08T04:53:12Z")

</div>

If the trailing dot is actually optional, you need to add a question mark in the proper place.

`$regexp(%album%,^.*\bVol(?:\.|ume)?\s*(\d+).*$,$1)`

---

<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:** [July 8, 2020, 7:49am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/20 "2020-07-08T07:49:46Z")

</div>

> [@dev91618](#):
>
> This is great, but does not work for situations  
> (Vol 5)  
> Vol 5,  
> Vol 5:

I would seriously consider an action group that unifies all these variations to just a single expression.

---

<div class="post-metadata">

**Author:** ![dev91618](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dev91618](https://community.mp3tag.de/u/dev91618)\
**Post date:** [July 8, 2020, 11:20am UTC](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490/21 "2020-07-08T11:20:11Z")

</div>

Hello, good day.  
Yes sure. But being very limited on regex I would need further help on how to remove brackets, colons, commas after the end of numbers. Isn't \s \W be replaced with something that can also take care of these. Basically in  
$regexp(%album%,^._\bVol(?:.|ume)?\s_(\d+).\*$,$1)  
when non-digits are encountered after we first encounter them after Volume, we should stop looking.  
Please accept my distinguished thanks for all the effort and attention.

> [@ohrenkino](#):
>
> I would seriously consider an action group that unifies all these variations to just a single expression.

[Next page](https://community.mp3tag.de/t/album-volume-to-discnumber-action-general-method-using-regexp/49490.md?page=2)
