INTERACT FORUM

Please login or register.

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

Author Topic: RegEx Help - How do I include a feild in a regex expression  (Read 2276 times)

Dan69

  • Recent member
  • *
  • Posts: 20
RegEx Help - How do I include a feild in a regex expression
« on: March 24, 2016, 05:45:15 pm »

I have Album titles with names like Mahler: Symphony No. 3 [Bernstein-2006]
I am looking to create a "normalized" version with the [Bernstein-2006] stripped off. The [Bernstein-2006] is comprised of 2 fields I have [Conductor Last Name] and [Date], with a "-" in the middle.
The problem is I also have albums with names like Greatest Hits [Live Edition]. In this case, I do *not* want to strip the [Live Edition] part of the title.
I'm trying to do this with a regex expression:
=clean(
clean(
      replace(
           [1PassCleanTitle], regex([1PassCleanTitle], /#\[([Conductor Last Name]-[Date])\]#/, 1, 0), )
), 0)
But the [Conductor Last Name] part does not appear to be resolving to the field value.

Any ideas on how to reference a library field from within a regex expression in MC?

Thanks -
Dan
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: RegEx Help - How do I include a feild in a regex expression
« Reply #1 on: March 24, 2016, 06:02:17 pm »

I think you're saying this:

1.  Look at the [Album] field.
2.  If it has something looking like this at the end: 
[somename-someotherstuff]
, then remove the end part.
3.  If it doesn't have that, then leave it as is.
4.  If it has something at the end like:
[some words without dashes]
, then leave that alone too.

If that's what you want, then this expression will do it, I believe:

Code: [Select]
if(Regex([album],/#(.+)(\[.+-.+\])#/,0,0),[R1],[album])
Try it as an expression column and see if it processes the [Album] tags properly.

Brian.
Logged

Dan69

  • Recent member
  • *
  • Posts: 20
Re: RegEx Help - How do I include a feild in a regex expression
« Reply #2 on: March 24, 2016, 07:08:02 pm »

Brian - thanks. This does solve the immediate problem I was having around cleaning the album field.

I still am curious though to see if there is a way to "build" a regex expression in MC that ultimately includes string values pulled from a field. Something akin to  /#\[([Conductor Last Name]-[Date])\]#/. At runtime this would translate to  /#\[(Bernstein-2009)\]#/, which would be exactly the expression I need for the file in question.

Thanks again! :)
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: RegEx Help - How do I include a feild in a regex expression
« Reply #3 on: March 24, 2016, 07:46:44 pm »

Building output expressions doesn't require regex.   You can just type what you want, using field names, and the expression language will fill it in correctly.

If you wanted to fill a field with [Conductor]-[Year] then you just put that in your expression and MC will fill it in.

Oh wait, I think I get it finally... you're trying to *search* with regex, using field contents *in* the Regex...  I'm pretty sure that's not possible because the characters you use in the Regex expression, the /# and #/ characters, are MC's escape characters.  These characters tell MC to treat everything in between as literal text and NOT do expression language substitutions.  So any field names like [Date] will not get translated, and will instead be taken literally.

Luckily you can get around this in most cases with other techniques.  If you come up with something else you need help with, just ask.

Good luck with your project.

Brian.

Logged

Dan69

  • Recent member
  • *
  • Posts: 20
Re: RegEx Help - How do I include a feild in a regex expression
« Reply #4 on: March 24, 2016, 08:35:20 pm »

That's what I thought, but I figured I would ask. I supposed I could build the regex in a variable, then try to use the variable. I'll tinker around with it some more.

I have a portable hard disk drive in my car with Microsoft Sync. It's very picky when it comes to how albums get named and its sort order is album name, track number only (using the tags). So for multidisc sets where there might be 2 different track #1, or for albums where different artists have the same name album, it is really flaky. So I've been working through way of mass renumbering tracks and mass renaming albums with expressions.

Thanks again.
Logged
Pages: [1]   Go Up