getmusicbee.com

General => MusicBee Wishlist => Topic started by: hiccup on February 03, 2017, 10:55:13 PM

Title: Full regex functionality for virtul tags.
Post by: hiccup on February 03, 2017, 10:55:13 PM
This is a request to have regex support within virtual tags.
Not a 'simple' true/false implementation, but full-fledged, so you can use more precise rules to create specific filtered, and/or replaced output.
Title: Re: Full regex functionality for virtul tags.
Post by: psychoadept on February 04, 2017, 05:11:41 AM
I'm not quite sure what you mean, but definitely +1 for a regex version of Replace.  Where else do you imagine it being used?
Title: Re: Full regex functionality for virtul tags.
Post by: hiccup on February 04, 2017, 08:59:51 AM
I'm not quite sure what you mean, but definitely +1 for a regex version of Replace.  Where else do you imagine it being used?

I tried to describe it briefly, and it seemed so clear in my own head ;-)

I am asking for it, specifically because I am currently running into some problems deriving 'Work, Parts, Acts, etc. from the titles of classical tracks.
http://getmusicbee.com/forum/index.php?topic=20209.msg123553#msg123553

For this I am making use of the delimiters , : - such a title should contain for this purpose.
My current virtual formulas seem to work quite well if these delimiters are present and occur not more than once each.
But as soon as a title contains more than one of those delimiters (such as in names, or longer and/or more refined or complicated names or sub-titles etc.) my formulas get confused rather easily.
I think it would be easier to tackle that problem using regex.

And it would probably also be easier to leave out parts of information from the title (or any other tag) that you don't want ending up in the virtual tag.
With the current options, you'll sort of have to reverse your thinking into: "to get the required output, what do I need to leave out first, what do I need to leave out next, what next, repeat, until you finally end up with the part you do want to end up with.
This also requires lots of nested commands, which tend to quickly fry my brain.
With regex the thought-process would be more humanoid-logical for this: "what do I want to have displayed?".

And finally, such a regex can very easily be tested on it's working by means of a regex tester. You will immediately and conveniently be able to see the result of anything you do with a regex.
The way of experimenting with formulas within MusicBee is no fun. As soon a you make the tiniest mistake in a formula, the tag panel will only say something like 'cannot parse', and you won't be able to see results that easy.
Title: Re: Full regex functionality for virtul tags.
Post by: psychoadept on February 04, 2017, 04:30:41 PM
That all makes sense, but which functions specifically would it apply to?

Any function that doesn't hook onto specific text in the tag wouldn't have any use for Regex.  So that gives us $Replace, $Split, and maybe $If (But $If is already covered by $IsMatch).  Am I overlooking anything?
Title: Re: Full regex functionality for virtul tags.
Post by: hiccup on February 04, 2017, 04:50:52 PM
The problem for me to oversee this and make some more specific suggestions or requests, is that there only is some vague hint that some regex functionality might be present for virtual tags, and that it might be used by using $IsMatch, and that that might give a True/False output.
Nobody confirmed this, nobody showed a working example.
I would like regex functionality that can give output that contains specific parts from a tag it sources from. Not just having an output saying True/False that will need to be made useful by the existing functions.

It's probably best to wait if Steven chimes in, otherwise we might be discussing and expecting things that can't or will not happen.
Title: Re: Full regex functionality for virtul tags.
Post by: Steven on February 04, 2017, 07:34:14 PM
i am happy to implement the regex.replace function where it would replace all matching instances in a field
Title: Re: Full regex functionality for virtul tags.
Post by: psychoadept on February 05, 2017, 01:39:02 AM
Awesome! That'll be a big help, and could be nested with $Split to make that work with a pattern.
Title: Re: Full regex functionality for virtul tags.
Post by: Steven on February 05, 2017, 12:28:21 PM
i have added:
Code
RxSplit(<field>,regex,index)
RxReplace(<field>,regex,replace-text)
note that replace-text can be literals or substitutions: https://msdn.microsoft.com/en-us/library/ewy2t5e0(v=vs.110).aspx

http://musicbee.niblseed.com/V3_1/MusicBee31_Patched.zip
Title: Re: Full regex functionality for virtul tags.
Post by: hiccup on February 05, 2017, 03:41:28 PM
That's great!
But.... I'm not sure I understand the working/syntax yet though.
Could you (or somebody else who is already getting this) perhaps give two quick examples of this would look like in real-life?

For example on a <Title> being:
"John ft. Mary (live)"

One example for what the virtual tag would look like if you want to have the output being just: (live)
and another one for what it would look like if you would want to only replace 'ft.' by 'feat.'
Title: Re: Full regex functionality for virtul tags.
Post by: Steven on February 05, 2017, 05:05:51 PM
i plan to enhance the virtual tag template editor so you can get a preview, so that should make things a bit better
Title: Re: Full regex functionality for virtul tags.
Post by: CritterMan on February 05, 2017, 05:08:56 PM
i plan to enhance the virtual tag template editor so you can get a preview, so that should make things a bit better

 :)
Title: Re: Full regex functionality for virtul tags.
Post by: hiccup on February 05, 2017, 05:11:04 PM
i plan to enhance the virtual tag template editor so you can get a preview, so that should make things a bit better

Wow, that would be really fantastic.
Title: Re: Full regex functionality for virtul tags.
Post by: theta_wave on February 05, 2017, 05:19:44 PM
That's great!
But.... I'm not sure I understand the working/syntax yet though.
Could you (or somebody else who is already getting this) perhaps give two quick examples of this would look like in real-life?

For example on a <Title> being:
"John ft. Mary (live)"

One example for what the virtual tag would look like if you want to have the output being just: (live)
and another one for what it would look like if you would want to only replace 'ft.' by 'feat.'

For (live), wouldn't the regex be (the terminal $ might be redundant, so it can be omitted)
Code
(^.*)(\([Ll]ive\)$)
Return code
Code
$2

For Foo ft Foo -> Foo (feat. Foo)
Code
(^.*)([Ff]eaturing|[Ff]t\.|Feat\.)(.*$)
Return code
Code
$1\(feat\.$3\)

For simply ft. (or Ft.) -> feat.
Code
[Ff]t\.
Return code
Code
feat\.

On a side note, I held my tongue on this wishlist thread since nothing happened (for some reason or another I'm not privy to) the last few times I made this request.  I just hoped that it would be incorporated finally and it appears that Steven did it.  I'm glad to see MB incorporating this feature and I'm looking forward to playing around with it.
Title: Re: Full regex functionality for virtul tags.
Post by: theta_wave on February 05, 2017, 05:46:48 PM
Early teething problems with $rxreplace.  The following code variations disappear after hitting save despite MB validating them as "OK".

Code
$RxReplace(<Title>,"(^.*?)(\: )(.*$)",$3)
Code
$RxReplace(<Title>,(^.*?)(\: )(.*$),$3)

Below returns the following, doesn't work and disappears when trying to use it in the thumbnail browser: $RxReplace(<Title>,""("^.*?")""("\:" "")""(".*"$"")"","$3")
Code
$RxReplace(<Title>,"(^.*?)(\: )(.*$)","$3")
Title: Re: Full regex functionality for virtul tags.
Post by: hiccup on February 05, 2017, 06:32:09 PM
On a side note, I held my tongue on this wishlist thread since nothing happened (for some reason or another I'm not privy to) the last few times I made this request.  I just hoped that it would be incorporated finally and it appears that Steven did it.  It is good to see MB incorporating this feature finally and I'm looking forward to playing around with it.

I can't tell you, but I am pretty sure this sort of thing is a matter of time (and timing). Now was probably a good moment for S. to invest his time and effort in it.
And thanks for your reply and feedback, that will be extremely helpful for me (and others) getting this to work.
Title: Re: Full regex functionality for virtul tags.
Post by: hiccup on February 05, 2017, 06:48:38 PM
Could you (or somebody else who is already getting this) perhaps give two quick examples of this would look like in real-life?
For example on a <Title> being:
"John ft. Mary (live)"
One example for what the virtual tag would look like if you want to have the output being just: (live)
and another one for what it would look like if you would want to only replace 'ft.' by 'feat.'

For (live), wouldn't the regex be (the terminal $ might be redundant, so it can be omitted)
Code
(^.*)(\([Ll]ive\)$)
Return code
Code
$2

For Foo ft Foo -> Foo (feat. Foo)
Code
(^.*)([Ff]eaturing|[Ff]t\.|Feat\.)(.*$)
Return code
Code
$1\(feat\.$3\)

I am not getting it. Stevens post mentions 'index', you have an entry that you call 'return code', I think I'm on a wrong path here.
Could you perhaps post a screenshot of how this should look in the virtual tag's edit panel?
Title: Re: Full regex functionality for virtul tags.
Post by: Steven on February 05, 2017, 07:16:53 PM
Early teething problems with $rxreplace.  The following code variations disappear after hitting save despite MB validating them as "OK".

Code
$RxReplace(<Title>,"(^.*?)(\: )(.*$)",$3)
there are two bugs. The parser should insist $3 is surrounded by quotes and when saving the quoting is not working correctly. Both should be fixed:

http://musicbee.niblseed.com/V3_1/MusicBee31_Patched.zip
Title: Re: Full regex functionality for virtul tags.
Post by: theta_wave on February 05, 2017, 08:50:56 PM
Could you (or somebody else who is already getting this) perhaps give two quick examples of this would look like in real-life?
For example on a <Title> being:
"John ft. Mary (live)"
One example for what the virtual tag would look like if you want to have the output being just: (live)
and another one for what it would look like if you would want to only replace 'ft.' by 'feat.'
I am not getting it. Stevens post mentions 'index', you have an entry that you call 'return code', I think I'm on a wrong path here.
Could you perhaps post a screenshot of how this should look in the virtual tag's edit panel?
Sorry about the confusion.  You're right, my "return code" is Steven's "replace-text".  Okay, after getting a handle on the formatting, your virtualtags should go something like this:

Title (Live) > (Live)
Code
$RxReplace(<Title>,"(^.*)(\([Ll]ive\))","$2")

Ft. (or Feat.) > feat. (note: you should probably do an if-contains first, like if the <title> contains ft. or Feat., then do below, else <title>)
Code
$RxReplace(<Title>,"(^.*)([Ff]t\.|Feat\.)(.*$)","$1\(feat\.$3\)")
Title: Re: Full regex functionality for virtul tags.
Post by: theta_wave on February 05, 2017, 08:54:08 PM
Early teething problems with $rxreplace.  The following code variations disappear after hitting save despite MB validating them as "OK".

Code
$RxReplace(<Title>,"(^.+?)(\: )(.*$)",$3)
there are two bugs. The parser should insist $3 is surrounded by quotes and when saving the quoting is not working correctly. Both should be fixed:

http://musicbee.niblseed.com/V3_1/MusicBee31_Patched.zip

Ok, it appears to work now, thanks!   :D

I have a quick question regarding the encapsulating quotation marks.  Would they have to be escaped in a regex formula?  Something like this?
Code
$RxReplace(<Title>,"(^.*)(\".*?\")(\:\s)(.*$)","$1\($2\)$3$4")
Title: Re: Full regex functionality for virtul tags.
Post by: Steven on February 05, 2017, 10:07:39 PM
this has the preview functionality in the template editor:
http://musicbee.niblseed.com/V3_1/MusicBee31_Patched.zip
Title: Re: Full regex functionality for virtul tags.
Post by: theta_wave on February 05, 2017, 11:55:30 PM
this has the preview functionality in the template editor:
http://musicbee.niblseed.com/V3_1/MusicBee31_Patched.zip
Wow, the preview functionality is quite nice.  I'll be reporting bugs with the regex function in the bug subforum.  Thanks Steven!
Title: Re: Full regex functionality for virtul tags.
Post by: hiccup on February 06, 2017, 08:27:16 AM
Sorry about the confusion.  You're right, my "return code" is Steven's "replace-text".

No problem, that was probably mostly my brain having a hard time getting the first gist of it all, and already going in lock-down mode after reading these (for me) not-to-familiar terms.
I am starting to get it, and getting it to work now. Great!
Title: Re: Full regex functionality for virtul tags.
Post by: Steven on February 07, 2017, 07:15:02 PM
for the next update i have enhanced the error handling to show the specific regex parsing error (if any) when clicking the preview button in the template editor

http://musicbee.niblseed.com/V3_1/MusicBee31_Patched.zip
Title: Re: Full regex functionality for virtul tags.
Post by: psychoadept on February 13, 2017, 04:55:20 AM
i plan to enhance the virtual tag template editor so you can get a preview, so that should make things a bit better

This is awesome! Loving it.
Title: Re: Full regex functionality for virtul tags.
Post by: marlonob on February 16, 2017, 11:07:23 PM
Is it possible to use the content of a <tag> (as a literal string) in the expression? I can’t figure out how.
Title: Re: Full regex functionality for virtul tags.
Post by: hiccup on February 17, 2017, 07:43:32 AM
I locked this topic. The wish was fulfilled.
Questions on the working of regex can be asked in the 'Questions' board, or here:
http://getmusicbee.com/forum/index.php?topic=20952.0