INTERACT FORUM

Please login or register.

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

Author Topic: Expression Help  (Read 359 times)

timwtheov

  • Galactic Citizen
  • ****
  • Posts: 354
Expression Help
« on: January 08, 2023, 11:17:21 am »

I have a cacluclated field [Composer Name Swap] with this expression someone created for me to swap composer names when there's a third term (i.e., "Ludwig van Beethoven" becomes "Beethoven, Ludwig van") or something like Johann Strauss II, which becomes "Strauss, Johann II:"

Code: [Select]
if(!regex([Composer], /#^([^,]+)\s+([^,]*?)$#/),
   [Composer],
   regex(listclean([Composer], 2, / ),
         /#^(?:(I+|[JS]r\.?)\s+)?([^ ]+)(.*)$#/, -1)[R2]/,/ listclean([R3], 2, / )[R1]
)

I also have a few composers with multiple names, e.g., "Al Piantadosi;Alfred Bryani;William Steffe" which show up like this:

"Steffe, Al Piantadosi, Alfred Bryani, William"

and some with just two names, such as "Paul Wright III;Lisa Shipman," which shows as "Shipman, Paul Wright III, Lisa"

Is it possible to modify the expression above to make these semicolon-delimited composers show as

"Piantadosi, Al, Alfred Bryan, William Steffe"

or

"Wright, Paul III, Lisa Shipman?"

Thanks for any all help!
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression Help
« Reply #1 on: January 08, 2023, 11:33:58 am »

https://yabb.jriver.com/interact/index.php/topic,133535.msg924988.html#msg924988
Code: [Select]
ListClean(
    ListMix(
        if(!Regex([L1], /#^([^,]+)\s+([^,]*?)$#/),
            [L1],
            Regex(ListClean([L1], 2, / ),/#^(?:(I+|[JS]r\.?)\s+)?([^ ]+)(.*)$#/, -1)[R2]/,/ ListClean([R3], 2, / )[R1]
        )
        ,,[Composer]
    )
    ,4
)&DataType=[List]
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression Help
« Reply #2 on: January 08, 2023, 12:19:27 pm »

Swap() now supports lists - this produces the same output in almost all cases, but doesn't handle Jr./Sr. suffixes:
Code: [Select]
swap([composer])
Logged

timwtheov

  • Galactic Citizen
  • ****
  • Posts: 354
Re: Expression Help
« Reply #3 on: January 08, 2023, 01:30:10 pm »

Thanks Lepa and Zybex!

I knew I'd asked about something regarding this previously, but I'd forgotten what. Anyway, I think the improved

Code: [Select]
Swap([Composer])
will do me well for now. The original expression used to slow down my main composers view a lot anyway, and the one Lepa proposed was taking almost 20 seconds to load each time, which probably wouldn't work for my impatience tolerance.
Logged
Pages: [1]   Go Up