# Custom Action - Opus Number

**URL:** <https://community.mp3tag.de/t/custom-action-opus-number/16371>\
**Category:** Support\
**Created:** [November 29, 2014, 10:07pm UTC](https://community.mp3tag.de/t/custom-action-opus-number/16371 "2014-11-29T22:07:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdemon](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@musicdemon](https://community.mp3tag.de/u/musicdemon)\
**Post date:** [November 29, 2014, 10:07pm UTC](https://community.mp3tag.de/t/custom-action-opus-number/16371/1 "2014-11-29T22:07:06Z")

</div>

This custom action will populate the custom field "OPUS" with information from both the filename and title fields. This field is most useful when cataloging classical music. Here are some examples of filenames/titles that this regex will match:

Opus 26, ludwig van beethoven - the song  
Sonate n. 14 op. 27, n. 2 in cis-moll  
IMSLP243517-beethoven-Op5no2-theblahsymphony  
JohannSebastianBach-29-GoldbergVariations,Bwv. 988-Variation28  
Ma vlast - JB. 1:112  
32 Variations in C minor, WoO 80  
String Quartet No. 15 in D Minor, K 421

Here's how it works:

a] populate OPUS tag with filename & title. Replace underscore for easier word boundaries  
**Field:** OPUS  
**Format Value:** $replace(%_filename% %title%,_,-)

b] check OPUS field for an sub-opus number  
**Regular Expression:** ^._\bop(?:us)?[-.\s]_(\d+)[,-.\s]_no?[-.\s]_(\d+)?.\*?$  
**Replace With:** $1/$2

c] check OPUS field for an opus number  
**Regular Expression:** ^._\bOp(?:us)?[-.\s]_?(\d+).\*?$  
**Replace With:** $1

d] check OPUS field for catalog number (common composer catalogs here)  
**Regular Expression:** ^._\b(BWV|JB|WoO|K)[-.\s]_([\d/:]+).\*?$  
**Replace With:** $1. $2

e] final regex: if field doesn't match our format, set it to null  
**Field:** OPUS  
**Format Value:** $regexp(%opus%,'(?\>^((?:\w+.?\s)?[\d/:]+)$|^.\*($))',$1)

Custom Action (save as .mta file in %appdata%\Roaming\Mp3tag\data\actions):

```
[#0]
T=5
F=OPUS
1=$replace(%_filename% %title%,_,-)

[#1]
T=4
F=OPUS
1=^.*\\\\bop(?:us)?[-\\\\.\\\\s]*(\\\\d+)[,-\\\\.\\\\s]*no?[-\\\\.\\\\s]*(\\\\d+)?.*?$
2=$1/$2
3=0

[#2]
T=4
F=OPUS
1=^.*\\\\bOp(?:us)?[-\\\\.\\\\s]*?(\\\\d+).*?$
2=$1
3=0

[#3]
T=4
F=OPUS
1=^.*\\\\b(BWV|JB|WoO|K)[-\\\\.\\\\s]*([\\\\d/:]+).*?$
2=$1. $2
3=0

[#4]
T=5
F=OPUS
1=$regexp(%opus%,'(?>^((?:\\\\w+\\\\.?\\\\s)?[\\\\d/:]+)$|^.*($))',$1)

```

A big thank you to Victor Kostas for [helping me](https://community.mp3tag.de/t/16300/1) with a tricky bit of regex!

---

<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:** [February 9, 2026, 12:25pm UTC](https://community.mp3tag.de/t/custom-action-opus-number/16371/2 "2026-02-09T12:25:23Z")

</div>

Closed on February 9, 2026, 12:25pm UTC


