Author Topic: Full regex functionality for virtul tags.  (Read 6308 times)

hiccup

  • Sr. Member
  • ****
  • Posts: 7787
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?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
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

theta_wave

  • Sr. Member
  • ****
  • Posts: 680
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\)")
Last Edit: February 05, 2017, 10:07:21 PM by theta_wave

theta_wave

  • Sr. Member
  • ****
  • Posts: 680
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")


theta_wave

  • Sr. Member
  • ****
  • Posts: 680
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!

hiccup

  • Sr. Member
  • ****
  • Posts: 7787
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!

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
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
Last Edit: February 07, 2017, 07:51:07 PM by Steven

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
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.
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

marlonob

  • Jr. Member
  • **
  • Posts: 43
Is it possible to use the content of a <tag> (as a literal string) in the expression? I can’t figure out how.

hiccup

  • Sr. Member
  • ****
  • Posts: 7787
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