INTERACT FORUM

Please login or register.

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

Author Topic: Expression Question  (Read 1964 times)

timwtheov

  • Galactic Citizen
  • ****
  • Posts: 354
Expression Question
« on: August 09, 2017, 08:25:32 pm »

Maybe blgentry can help here.

I have [Composer] in my classical albums in the form of "Last Name, First Name (Birth-Death Date)" (e.g., Beethoven, Ludwig van (1770-1827)), and since I'm in the middle of changing some things tagging-wise, I've been trying to build an expression (probably a regex of some kind) that "grabs" the birth and death dates from between the parentheses in [Composer] (including dates where the composer hasn't died yet, e.g., Auerbach, Lera (1973)) and puts them in a custom field, say [ComposerDates]. I tried something like

Code: [Select]
regex([Composer], /#(() (.+)#/, 2, 0)
as the expression for my custom field, but it's not working. At minimum, I realize that the left parenthesis inside Reference 1 is probably wrong (likely throwing off the parenthesis groupings) and also that I hadn't accounted for the ending parenthesis, but at least I was hoping to get something like 1770-1827) in [ComposerDates].

Any suggestions? Thanks much!
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9139
Re: Expression Question
« Reply #1 on: August 10, 2017, 06:25:27 am »

Another case where "fill properties from properties" would be handy to have...

I'm pretty sure you could do this using regex, but, I can't help with that as regex is a bit beyond me :)

Is that information contained (consistantly) in the filename too?
If it is, you can use the "Fill properties from filename" tool to populate the [ComposerDates] field.

fx:
Beethoven, Ludwig van (1770-1827) - Track name.flac

Using the 'Template' driven part of the tool rather than automatic, the template below:
[] ([ComposerDates]) - []

would place the data between parenthesis into [ComposerDates] and ignore all other data. (Using 'filename' only is assumed, directories would be unchecked.)

A regex wiz may drift by with regex solution soon... :)

timwtheov

  • Galactic Citizen
  • ****
  • Posts: 354
Re: Expression Question
« Reply #2 on: August 10, 2017, 11:02:39 am »

Thanks, Marko. They're not in the filenames, though. I ripped these discs long before I knew much about tagging. This format for [Composer] is from Musichi, which I only started using a couple of years ago. So I think it's going to have to be Regex.

[Edit] And yes, it would be GREAT to have a "Fill Properties from Properties" tool of some kind.
Logged

Daydream

  • Citizen of the Universe
  • *****
  • Posts: 771
Re: Expression Question
« Reply #3 on: August 10, 2017, 12:31:35 pm »

Assuming the years are always in parenthesis:

Code: [Select]
regex([Composer], /#(.*)\s\((.*)\)#/,2,0)
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Expression Question
« Reply #4 on: August 10, 2017, 04:39:48 pm »

As Daydream, I'm assuming these always have parenthesis.  This regex accounts for having one date or two dates, and makes them available separately (with modifications).  If all you want is the stuff between the parenthesis it's probably even easier than I'm making it.  I was sorta assuming you might want a birth and death date separately.

Is there something other than just grabbing the stuff between parenthesis?

Anyway, here's my slightly overly complicated expression:

Code: [Select]
regex([Composer],/#\(([0-9]+)[\s,-]*([0-9]+)?\s*\)#/,-1,0)[R1]if(!isempty([R2]),/ - [R2],)
Brian.
Logged

timwtheov

  • Galactic Citizen
  • ****
  • Posts: 354
Re: Expression Question
« Reply #5 on: August 10, 2017, 06:40:11 pm »

Thanks Daydream and blgentry!

Both work, though blgentry's doesn't have a space after the last digit. I really just wanted everything in parentheses because I'm changing how [Composer] is populated (moving to AMG for classical tag population instead of Musichi, which I find cumbersome because of major gaps in their database of composers and compositions and a couple of other reasons). I do like having a composer's birth and dates, however, just not in the same tag as [Composer].

Thanks again!
Logged
Pages: [1]   Go Up