Author Topic: [6245] Sorting/escaping quotation marks w/ ignore words & $RxReplace  (Read 2644 times)

theta_wave

  • Sr. Member
  • ****
  • Posts: 680
First of all, thanks Steven for adding $RxReplace and $RxSplit to Musicbee's family of functions.  I'm really excited to mess around with them.  Here, I'm trying to find my way around sorting Titles that begin with quotation marks.  I'm finding that "ignore words" doesn't recognize quotation marks and $RxReplace and $IsMatch functions have issues with escaped quotation marks.

Here's what I'm trying to sort:




1) Ignore Words (Preferences > Sorting/Grouping > ignore words) [my preferred way]

I tried to add the quotation mark in the ignored words list (my preferred way).  My array:
Code
The, :, {, (, ., [, "

I also tried Bee-liever's array:
Code
The, &, ..., "..., ", ', [, ], #, (, ), >, <, …

Unfortunately, both arrays failed.

2) Try removing quotation marks with $rxreplace after matching titles that begin with them.

Generally, I'm doing the following with a virtual tag for <Title> (note, I don't want to replace quotation marks in Titles that don't start with one):

Symphony No.1 in E minor, K.943: I. Allegro
Symphony No.12 in B minor, K.359: I. Andante
Symphony No.7a in C Major ("Der Foo"), K.334: I. Allegro
Foo opera, K.123: Act. I, Scene II: Aria
"Ach, was müssen wir erfahren!", K.43a
"Ah più tremar non voglio", K.71

What I'm trying to do is make them look like this in the left panel (thumbnail browser):

Symphony No. 1 in E minor, K.943
Symphony No.12 in B minor, K.359
Symphony No. 7a in C Major ("Der Foo"), K.334
Foo opera, K.123
Ach, was müssen wir erfahren!, K.43a
Ah più tremar non voglio, K.71

The ideal $rxreplace virtualtag to handle everything would be this: $RxReplace($RxReplace($RxReplace(<Title>,"(^.*?)(\: )(.*$)","$1"),"(^.*?)(No\.)(\d{1}\s|\d{1}[^0-9]\s)(.*$)","$1$2 $3$4"),"(^\")(.*)(\")(,)(.*$)","$2$4$5")

Unfortunately, the bolded underlined regex does not work (it works in notepad++).

So, I tried the following that works in the first instance (preview looked good and MB validated the formula): $If($IsMatch(<Title>,"(^\")(.*)")="T",$Replace(<Title>,"\"",),$RxReplace($RxReplace(<Title>,"(^.*?)(\: )(.*$)","$1"),"(^.*?)(No\.)(\d{1}\s|\d{1}[^0-9]\s)(.*$)","$1$2 $3$4"))

However, I noticed a red exclamation mark in the virtualtag menu when re-opening the preferences and now it stated it had an error.  It appears that MB removes the escape character causing the error to show up (bolded underlined): (^\")(.*) -> (^")(.*)

Anyways, my preferred way to handle this is to figure out how to have "ignore words" recognize quotation marks.  The reason why is that I'm afraid that messing around with how MusicBee handles escaped quotation marks in regex might have unintended consequences down the line (e.g. screwing up other people's existing virtualtags).

EDIT: The following scheme works, but it is rather inelegant: $If($IsMatch(<Title>,"^[^0-9A-Za-z]")="T",$Replace(<Title>,"\"",),<Title>)
How it is implemented in my virtualtag: $If($IsMatch(<Title>,"^[^0-9A-Za-z]")="T",$Replace($RxReplace($RxReplace($RxReplace(<Title>,"(^.*?)(\: )(.*$)","$1"),"(^.*?)(No\.)(\d{1}\s|\d{1}[^0-9]\s)(.*$)","$1$2 $3$4"),"(^.*?)(B\..+?|D\..+?|G\..+?|Hob\..+?|K\..+?|Op\..+?|R\..+?|RV\s.+?|S\..+?)(\s\(.+?\))$","$1$2"),"\"",),$RxReplace($RxReplace($RxReplace(<Title>,"(^.*?)(\: )(.*$)","$1"),"(^.*?)(No\.)(\d{1}\s|\d{1}[^0-9]\s)(.*$)","$1$2 $3$4"),"(^.*?)(B\..+?|D\..+?|G\..+?|Hob\..+?|K\..+?|Op\..+?|R\..+?|RV\s.+?|S\..+?)(\s\(.+?\))$","$1$2"))

Still, I think it would be easier if "ignore words" worked, as I do like seeing the quotation marks and have them sorted according to the settings.  Am I missing something here?
Last Edit: February 06, 2017, 08:27:48 AM by theta_wave

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34362
quotes should be fixed for the next update.
I tested with:
Code
$If($IsMatch(<Title>,"(^\")(.*)")="T",$Replace(<Title>,"\"",),$RxReplace($RxReplace(<Title>,"(^.*?)(\: )(.*$)","$1"),"(^.*?)(No\.)(\d{1}\s|\d{1}[^0-9]\s)(.*$)","$1$2 $3$4"))
the " char will now be forced to \" when saved


theta_wave

  • Sr. Member
  • ****
  • Posts: 680
http://musicbee.niblseed.com/V3_1/MusicBee31_Patched.zip

Thanks Steven, the patch [6246] worked well with the regex you tried.  However, the following regex (shortened version from the OP) does not appear to be saved properly (validated "OK" > save > apply & save > reopen):

$RxReplace(<Title>,"(^\")(.*)(\")(,)(.*$)","$2$4$5")

to

$RxReplace(<Title>,"(^)(.*)()(,)(.*$)","$2$4$5")

I'm not using this particular regex, as $IsMatch and $Replace together are suitable for the job I had in mind.  I just wanted to bring this issue up because I spotted it and others might have a use for escaping quotes under $RxReplace.
Last Edit: February 09, 2017, 07:10:46 PM by theta_wave

Steven

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

theta_wave

  • Sr. Member
  • ****
  • Posts: 680
thats fixed for the next v3.1 update

http://musicbee.niblseed.com/V3_1/MusicBee31_Patched.zip
Thanks Steven.  I just tested 6249 and $RxReplace(<Title>,"(^\")(.*)(\")(,)(.*$)","$2$4$5") is saved properly now.