Custom Action - Opus Number

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 with a tricky bit of regex!