INTERACT FORUM
More => Old Versions => JRiver Media Center 18 for Windows => Topic started by: jctcom on August 10, 2013, 12:00:09 am
-
I am sure we all remember the wonderful expression that you guys helped me with to create an automatically generated "AlbumArtistSort" field.
In case not here is it: if(regex([Album Artist], /#(The|A|El) +(.*)$#/), [R2]/, [R1], [Album Artist])
So far it has been working great!
Just came up against a weird glitch though. For the Album Artist: "Magna Carta" it is giving me "Carta, a"
Strange thing is that I use the same expression to create an "Artist Sort" field and that one seems to be working correctly.
Any ideas?
(Remember I never claimed to fully understand the expression in the first place lol.)
Carl.
-
Oops I lied. it is doing the same thing for "ArtistSort" as well. Still though the expression specifies "The, A and El" This Artist definitely does not start with any of those.
Carl.
-
Make this change:
if(regex([Album Artist], /#^(The|A|El) +(.*)$#/), [R2]/, [R1], [Album Artist])
-
Amazing! 1 little "^" fixes everything.
I have no clue why but it now works.
Is there a layman's way to explain why it decided to do that in the first place with that specific group?
Carl.
-
Sure. The regular expression really wants to match something. And I had failed to force it to match only at the beginning of the line. That's what the ^ does.
The expression looked for a "The" or "A" or "El" anywhere in the line, followed by one or more spaces, followed by anything else. So it found the "a" at the end of "Magna", followed by the space, followed by "Carta":
Magna Carta
Placing the anchor ^ at the beginning of the RE forces the match to start at the beginning of the string.
You might also consider if you need to enable case-sensitivity, as the default is not case sensitive in MC:
if(regex([Album Artist], /#^(The|A|El) +(.*)$#/, 0, 1), [R2]/, [R1], [Album Artist])
We have to also supply the 0 now, which means use the test mode if regex(). The 1 is the case sensitive flag.
-
Cool. I think I even understood that.
Are you missing the "^" in that last example?
Carl.
-
Yup, I copy/pasted from the first post instead of the corrected one. Fixed. Good catch.