INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: regex() string manipulation on MAC  (Read 2931 times)

MartinG

  • Junior Woodchuck
  • **
  • Posts: 58
regex() string manipulation on MAC
« on: December 18, 2019, 12:26:02 pm »

Hi.
Any advice is welcome.
Actually I can't get the regex() manipulation work on a MAC, while it works perfectly in a Windows environment. This is what the complete string looks like:

Left(MoveArticles([Album]),1)\regex(replace([Album],:, / /-),/#([^\s,]+)#/,-1,1)[R1]\ replace([Album],:, / /-) - if(isequal([Dirigent], Unbekannt Dirigent),[Albuminterpret], if(isequal([Albuminterpret],if(isequal(Left([Dirigent],3),Sir),removeleft([Dirigent],4),[Dirigent]),1), regex(Swap([Albuminterpret]),/#([^\s,]+)#/,-1,1)[R1]/, [Orchester], regex(Swap([Albuminterpret]),/#([^\s,]+)#/,-1,1)[R1]/, regex(Swap([Dirigent]),/#([^\s,]+)#/,-1,1)[R1]/, [Orchester])) ([Abtastrate])

While it is clear that a backslash has to be replaced by a slash to force a directory change on MAC, the regex form
regex(replace([Album],:, / /-),/#([^\s,]+)#/,-1,1)[R1]
generally does not work on MAC.
To my assumption the slashes generally cause the problem and are not accepted in a MAC environment. But how can I force a blank space in replace([Album],:, / /-) and how can I build an expression in regex() when it is not possible to use /# and #/ to surround the entire regular expression?

Thank you for any hint or help.
Martin
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: regex() string manipulation on MAC
« Reply #1 on: December 18, 2019, 01:19:32 pm »

It's unclear to me what you are trying to do.  The expression at the top is pretty big!  :)

If you can break this down to the interior expression that you are having trouble with, and explain exactly what the expected input and output is, I might be able to help.

I believe that forward slash is the escape character in MC.  So to print a literal slash, you need two of them, like // .  You can also make any expression use a literal string.   You can also use /#literal text here#/ in ANY expression (not just regex).  See the notes here for more info:

https://wiki.jriver.com/index.php/Expression_Language#Expression_Language_Syntax

Maybe some of that will get you started towards your solution.  If you would like me to try to help, please post more information as I requested above.

Good luck.

Brian.
Logged

MartinG

  • Junior Woodchuck
  • **
  • Posts: 58
Re: regex() string manipulation on MAC
« Reply #2 on: December 18, 2019, 03:39:12 pm »

Hi Brian.
Thank you for the quick reaction. Actually the jriver wiki is well known to me an what you see is the result of intensive study and learning by doing.  ;D
OK, I try to explain my problem in different words.
To move files from disk A to disk B in a specific file structure, I use the jriver tool "Rename, Move & Copy Files". Within the dialogue you have the option to define directories, which I did and which works as wanted with the given long expression I copied for explanation into my text. However, this expression works pretty well and does what it is aimed to do for when I use the jriver Windows version inside the Windows surrounding.

But I do have a master license as there are also MAC computers in my home and I definitely prefer to work with a MAC. So all my music is organized and stored on a MAC.

Unfortunately the jriver wiki is focussed on Windows machines, so the help for MAC users is limited in terms of working with slashes. Again: The expression I wrote works well on a Windows computer... but definitely not on jriver for MAC.

As it is clear to me, that a backslash inside a MAC system has to be replaced by a slash to force a directory change, I replaced all backslashes by slashes where needed... but this did not lead to a well functioning script in the MAC surrounding! In the Windows surrounding the slash sign is used for different needs, as you already wrote. However, I do have to translate the script for my jriver MAC version and do not know how to replace the / sign.

To be more clear: The regex() command uses /# and #/ to surround the entire regular expression. But the MAC is not able to "understand" this. So it is with the / inside the integrated command replace([Album],:, / /-), where the / also is misinterpreted.
If you insert the expression in your Mediacenter, you will see what it does (as far as you use jriver either in the German translation or translate words like "Dirigent" by "Conductor" and so on).
However, if you just take the expression "replace([Album],:, / /-)"... meaning replace the : by a gap plus a - when found in the Album title, you will see that even this simple command does not work on a MAC. The jriver MAC version seems to think, that you want to change directory twice or somewhat like this while the Windows machine exactly knows what to do.

Example:
While within Windows the term "Beethoven: Symphony No. 9" gets conversed correctly into "Beethoven - Symphony No. 9", with a MAC system the preview windows shows that it is going to make a sub-sub-folder like this "Beethoven//- Symphony No. 9". And with a more complex phrase like regex(replace([Album],:, / /-),/#([^\s,]+)#/,-1,1)[R1] the system can't work at all and completely gets confused.

Long talk, short sense:
How can I get the MAC version understanding the / correctly inside an expression? This is my problem.
Hope it got more clear now.
Thanks for your help.
Martin
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: regex() string manipulation on MAC
« Reply #3 on: December 18, 2019, 05:34:20 pm »

I understand a little more now.

This is complicated because RM&C does weird stuff with expressions.  I have had numerous instances where I tried to write expressions and then use them in RM&C.  In expression columns, the expressions work correctly.  But once inside RM&C they don't do what I expect.

Expression columns are the primary way I test expressions.  That way I can quickly develop the expression I need, modify it, see my results, and interrate until I get it right.

I just tried your simple "replace" expression in an expression column.  I expected it to do weird stuff.  But it worked!  I also tried this version, which also worked well:

Code: [Select]
replace([Album],:, /# -#/)
I didn't know exactly what to do with RM&C to test that.  It gets more complicated:  You see, RM&C has some "magic" built in to it.  For example, when RM&C sees the colon character ( : ) in a filename (anywhere in the file name) it replaces it with an underscore character ( _ ) .  So I'm not even sure that your expression applies. Meaning that, in the filename itself, you should never see a colon character, because they aren't legal in the windows file system and MC already translates them to underscores.  So...  I'm left a bit confused.

I'm not sure how to advise you on this... I'm pretty good with expression language, but RM&C makes it very, very confusing.  First because of it's magic behavior.  Second because it's done lots of weird stuff with expressions in the past.

Brian.
Logged

MartinG

  • Junior Woodchuck
  • **
  • Posts: 58
Re: regex() string manipulation on MAC
« Reply #4 on: December 19, 2019, 09:35:06 am »

Mhmmm... OK, let's do it with this simple example.
replace([Album],:, /# -#/)
If I insert the suggested line into my version of JRiver (25.0.114, 64bit running on MAC OS Sierra 10.12.6) in the RM&C dialog, the result looks like the screenshot I attached. So, this also does not work with a MAC.
However, now it should get clear what I try to do...
I just want to do the same with my JRiver MAC version, what I am able to do with the Windows version. AND PLEASE don't tell me: Use the Windows version if it works over there.  ;)
THIS is no option for me and only is a workaround as it does not work with the MAC at the moment.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: regex() string manipulation on MAC
« Reply #5 on: December 19, 2019, 11:43:54 am »

Mhmmm... OK, let's do it with this simple example.

This was very helpful.  Thank you for making it simple so we can get to the core of the issue.  :)

Quote
replace([Album],:, /# -#/)
If I insert the suggested line into my version of JRiver (25.0.114, 64bit running on MAC OS Sierra 10.12.6) in the RM&C dialog, the result looks like the screenshot I attached.

Agreed.  This behavior is wrong and not at all what you would expect.  This is some of the "weird stuff that RM&C does" that I was explaining.  It mangles certain kinds of expressions and I don't know why.  I think it has to do with the path separator being slash *and* the escape character being slash.  It messes up the interpretation of these characters.

Quote
I just want to do the same with my JRiver MAC version, what I am able to do with the Windows version. AND PLEASE don't tell me: Use the Windows version if it works over there.  ;)

I'm probably the last person to tell you to go use Windows.  :)
I agree that you would expect your expression from Windows to work on Mac.  Again, I think it's because of the path separator being slash.  Which is almost exactly what you said in your first post actually.

So here's a workaround that I just tried and it works:

1.  Go to manage library fields and define a new field as Calculated Data.  I called mine [a2].  You can call yours something more meaningful.
2.  Set this as the value for that field in calculated data:
Code: [Select]
replace([Album],/# -#/)3.  Now go back to RM&C and insert your new field anywhere you need the "translated album value".  It will use the correct characters, replacing the colon.

You can just substitute your new field name everywhere in your original expression that had the "replace" clause.  I think that will mostly work for you.  More comments in my next post.

Brian.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: regex() string manipulation on MAC
« Reply #6 on: December 19, 2019, 11:47:56 am »

I think this new field [a2] will also work in your regex.  But if it doesn't, maybe I can help you figure out an alternate.  I believe your regex is simply extracting the first word from it's argument.  So the first word of the [Album] in most cases and the first word of something else in other cases.

Let me know if this works, and if not, we can try to figure it out.

Good luck.

Brian.
Logged

MartinG

  • Junior Woodchuck
  • **
  • Posts: 58
Re: regex() string manipulation on MAC
« Reply #7 on: December 19, 2019, 11:55:45 am »

OK... I will try this.
Do I have to use your modified expression or can I also do it with my original Windows expression replace([Album],:, / /-) ??

Just a quick off topic (concerning MAC vs Windows version):
Having both computers in the same LAN and same switch towards the NAS ... well - no exaggeration - the MAC is round about 10 times faster in extracting Folder.jpg covers from inside the NAS drive compared to the Windows version (Windows 10, i9 CPU, same JRiver version)!!!
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: regex() string manipulation on MAC
« Reply #8 on: December 19, 2019, 12:10:29 pm »

OK... I will try this.
Do I have to use your modified expression or can I also do it with my original Windows expression replace([Album],:, / /-) ??

I just switched my [a2] to use your definition instead.  It worked the same as mine.

Regarding the speed difference you see, I don't have anything to add.  It's surprising though, that's for sure.

Brian.
Logged

MartinG

  • Junior Woodchuck
  • **
  • Posts: 58
Re: regex() string manipulation on MAC
« Reply #9 on: December 19, 2019, 12:45:19 pm »

Ha! If you could see me now... I have a big smirk from my left ear to my right ear.  ;D
It's working!
Dirty hack, but it's working.
Thanks a lot for the help. Highly appreciated!!!!!
Thank you.
Have some wonderful X-mas days.

Martin

P.S.:
Final note for anybody who is interested in the meaning of the loooooong expression of my first post...

First step:
Extract the first letter of the album title (e.g. Beethoven: Symphony No. 9) to build a main directory (in this case "B")

Second step:
Take the name of the Album which is written before the : and build a subfolder (in this case "Beethoven")

Third step:
As we now have built Volume/B/Beethoven the next step is to build a Foldername that is descriptive for the relevant classical Album. Thus we take again the original [Album] value, replace the : by a - and check, if there is a conductor defined or not. If there is no conductor the expression takes the album artist as relevant value.
IF there is a conductor defined, the expression now checks, if conductor and album artist is the same (to avoid double naming). In our case let's take "Herbert von Karajan" as conductor and also as album artist. In case the album artist is somebody else (in case of piano concerts it could be e.g. Alfred Brendel), the expression first will take the second name of the album artist, followed by a comma, then the second name of the conductor, followed by a comma and finally take the value [Orchestra]. The final information of this expression is the album sample rate (to differentiate between hires albums and normal 44.1 albums).

That means, a final directory could look like this:
Volume/B/Beethoven/Beethoven - Symphony No. 9 - Karajan, Berliner Symphoniker (44.1)
or like this
Volume/B/Beethoven/Beethoven - Piano Concerto No. 5 - Brendel, Haitink, London Philharmonic Orchestra (44,1 kHz)

Now it should be clear what the expression is doing. :)
But take care... the expression is not finalised yet and there is still little work to do to handle albums with various artists or various conductors.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: regex() string manipulation on MAC
« Reply #10 on: December 19, 2019, 03:10:52 pm »

I'm very happy to hear it worked for you.  :)

Happy holidays to you too. 

Take care,
Brian.
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13813
Re: regex() string manipulation on MAC
« Reply #11 on: December 22, 2019, 05:45:52 pm »

I just switched my [a2] to use your definition instead.  It worked the same as mine.

Regarding the speed difference you see, I don't have anything to add.  It's surprising though, that's for sure.

Brian.
The regex code was causing problems in the new compiler so we had to drop back to the Posix version, I think it's ok now and will be updated in the next build.
Logged
Pages: [1]   Go Up