Author Topic: Useful regex formulas  (Read 8157 times)

Bee-liever

  • Member
  • Sr. Member
  • *****
  • Posts: 3830
  • MB Version: 3.6.8830 P
With more regex support in MusicBee 3.1, this post is for sharing regular expressions that users have found useful
Please do not post questions here about providing specific regex's
As always, these go in the Questions sub-forum
MusicBee and my library - Making bee-utiful music together

Bee-liever

  • Member
  • Sr. Member
  • *****
  • Posts: 3830
  • MB Version: 3.6.8830 P
With the change in 3.1 of moving the Musicians Credits into the Artists Splitter, where they are all combined into the Artists: Performer catergory (see post here), I needed a way to only show the entries that were in the "Artist (role/instrument)" format.
This is the virtual tag I used:
Code
$Replace($RxReplace(<Artists: Performer>,"(?:([^;\(]*\([^\)]*\))(?:;|$))|([^;\(\)]+(?:;|$))","$1"),")",");")
Last Edit: February 27, 2017, 11:01:25 PM by Bee-liever
MusicBee and my library - Making bee-utiful music together

vzell

  • Sr. Member
  • ****
  • Posts: 427
The following regexp extracts just the "Producers" from the <Artists: Performer> category and can be used for a virtual tag

Code
$Replace($Trim($RxReplace(<Artists: Performer>,"([^;\(]*\(producer\))|(?:([^;\(]*\([^\)]*\))(?:;|$))|([^;\(\)]+(?:;|$))","$1"))," (producer)","")
or more generally:

Code
$Replace($Trim($RxReplace(<Artists: Perfromer>,"([^;\(]*\(ROLENAME\))|(?:([^;\(]*\([^\)]*\))(?:;|$))|([^;\(\)]+(?:;|$))","$1"))," (ROLENAME)","")
Last Edit: March 23, 2017, 11:03:12 AM by vzell

redwing

  • Guest
These are two regex formulas to extract performers name & role/instrument name (working for multi-value tags as well) to be used as filtering category.

For <Artists: Performer> tag value

"Paul McCartney (electric bass guitar); Ringo Starr (drums); George Harrison (electric guitar)"

Code
$IsNull(<Artists: Performer>,,$RxReplace(<Artists: Performer>,"([^;\(]*)\([^;\)]*\)","$1"))
returns "Paul McCartney;Ringo Starr;George Harrison"

Code
$IsNull(<Artists: Performer>,,$RxReplace(<Artists: Performer>,"[^;\(]*\(([^;\)]*)\)","$1"))
returns "electric bass guitar;drums;electric guitar"
Last Edit: July 08, 2017, 05:55:19 PM by redwing

karbock

  • Sr. Member
  • ****
  • Posts: 320
Special title formatting

A regex I use to format titles, especially for audio files with a CUE sheet, where it is not possible to specify <Movement#> and <MovementName> for each track.

Possible title content expected in input:

Title formatTitle contentResulting display
TextProtector of the Common FolkProtector of the Common Folk
#. Text
or #letter. Text
or P#letter. Text
1. Adagio
12c. Chinese dance
P3.12. Seid froh dieweil
1. Adagio
12c. Chinese dance
P3.12. Seid froh dieweil
(Text) Text(Encore) Wien, Wien, nur Du allein(Encore) Wien, Wien, nur Du allein
Number+letter. (Text) Text4b. (Choir) O Freunde, nicht diese Töne!
4b. (Choir) O Freunde, nicht diese Töne!


Code
{font: Ubuntu;Italic;12}{color: 0,105,155}$RxReplace(<Title>,"^(P?[0-9.]+[a-z]*[.] )?([(][^)]*[)])?(.*)","$1"){color: 20,125,20}$RxReplace(<Title>,"^(P?[0-9.]+[a-z]*[.] )?([(][^)]*[)])?(.*)","$2"){font: default}{color: default}$RxReplace(<Title>,"^(P?[0-9.]+[a-z]*[.] )?([(][^)]*[)])?(.*)","$3")

$RxReplace is called three times, because it is not possible to insert the formatting codes directly into the replacement string.

Adapt to your taste and MB skin:
- {font: Ubuntu;Italic;12} and {font: default}
- {color: r,g,b} and {color: default}
Last Edit: July 29, 2023, 11:24:22 AM by karbock

phred

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 9303
See https://getmusicbee.com/forum/index.php?topic=38817.0 for a discussion and list of all regular expressions
Download the latest MusicBee v3.5 or 3.6 patch from here.
Unzip into your MusicBee directory and overwrite existing files.

----------
The FAQ
The Wiki
Posting screenshots is here
Searching the forum with Google is  here