Author Topic: regex matching functionality for virtual tags  (Read 2361 times)

hiccup

  • Sr. Member
  • ****
  • Posts: 7888
MusicBee has regex functionality for virtual tags that can replace specific parts of the contents of a tag. ($RxReplace)

It could be useful to additionally have regex functionality that can just match a given regex.
Two examples where this could be useful:

The Musician Credits (TMCL) tag can contain all sorts of instrumentalists such as bass, drums, vocals, violin, etc.
Using a $RxMatch would allow to create a virtual tag that only contains the violin player, the guitar player, or perhaps the whole rhythm section. (bass, drums, rhythm guitar)

MusicBrainz offfers several 'identifiers' such as:
musicbrainz_artistid, musicbrainz_originalalbumid, musicbrainz_workid, _recordingcomment, _performance_attributes and many more.
(I believe there currently are at least 15 different ones)
Not to waste custom tags for each and every single one of them, you can concatenate them into one custom tag.
You can then extract the ones you want to use by using some nested splitting, but a regex could be better up for that task.

These are just two examples that came up thinking about this, but I am sure creative minds can come up with other useful purposes?

Thoughts?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34362
There is already:
$IsMatch(<field>,regex-pattern)

I appreciate its not named consistently with the other RegEx functions

hiccup

  • Sr. Member
  • ****
  • Posts: 7888
Thnx, I think I tried that out in the past, but doesn't that produce only either a T(rue) or F(alse)?
Is it possible to make it output the matched value somehow?

So if 'performer' contains 'bass: Jack Jones', don't output 'T', but 'Jack Jones'?

The Incredible Boom Boom

  • Sr. Member
  • ****
  • Posts: 1280
I do the above with a series of $RxReplace and $Replace functions, which in turn makes the tags they're incorporated within fairly complicated, so it would be nice to have this addition. +1

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34362

The Incredible Boom Boom

  • Sr. Member
  • ****
  • Posts: 1280
Thanks for implementing this in v3.4.

Would it be possible to have $RxMatch return just what's within capture groups? Right now, if "<ENSEMBLE>=orchestra:Philadelphia Orchestra; choir:Philadelphia Boys Choir & Chorale", then...
Code
$RxMatch(<ENSEMBLE>,"orchestra:(.+);")
returns "orchestra:Philadelphia Orchestra," which is immensely helpful, but if it's possible to return capture groups if they're used, that would be perfect.

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2459
Right now, if "<ENSEMBLE>=orchestra:Philadelphia Orchestra; choir:Philadelphia Boys Choir & Chorale", then...
Code
$RxMatch(<ENSEMBLE>,"orchestra:(.+);")
returns "orchestra:Philadelphia Orchestra,"

Does this also work for you to extract just the choir details? I had mixed results depending on whether I was matching the first or second substrings.


On the other hand, I'm not sure that's how RxMatch is supposed to work.
From Steven's latest 3.4 update post:

Quote
$RxMatch(<field>,regex-pattern) function that returns true if a field matches a regex pattern

So why is it returning the matched strings some of the time?
Bee excellent to each other...

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34362
that statement was a mistake - i am pretty sure its returning the string for the match conditions

The Incredible Boom Boom

  • Sr. Member
  • ****
  • Posts: 1280
that statement was a mistake - i am pretty sure its returning the string for the match conditions

Yeah, that's how it's working and figured what you likely meant.

Right now, if "<ENSEMBLE>=orchestra:Philadelphia Orchestra; choir:Philadelphia Boys Choir & Chorale", then...
Code
$RxMatch(<ENSEMBLE>,"orchestra:(.+);")
returns "orchestra:Philadelphia Orchestra,"

Does this also work for you to extract just the choir details? I had mixed results depending on whether I was matching the first or second substrings.

That was just something I made up as a quick example, but yeah, the last string in a multi-field doesn't have a semi-colon, so capturing fails and returns the entire string.

Code
$RxMatch(<ENSEMBLE>,choir:(.+?)(?:;|$)")
will let you grab the choir group from wherever it is in a multi-field tag.

Code
$Replace($Replace($RxMatch(<ENSEMBLE>,"choir:(.+?)(?:;|$)"),;,),choir:,)
In full it's (for now) a little unwieldy looking, but if just the capture groups can be returned, only one $Replace statement would be needed.

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2459
I think the RxSplit function will do what you want.
Try this:

Code
$RxSplit(<Ensemble>,"choir:(.+?)(?:;|$)",2)
Bee excellent to each other...

The Incredible Boom Boom

  • Sr. Member
  • ****
  • Posts: 1280
I think the RxSplit function will do what you want.
Try this:

Code
$RxSplit(<Ensemble>,"choir:(.+?)(?:;|$)",2)

Works great, thanks. My previous function had been an $RxReplace, and I was so caught up trying to get the new one to work (simply just to save characters in my Virtual Tags) I didn't even consider splitting.