INTERACT FORUM

Please login or register.

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

Author Topic: Calling Expression Language experts - removing bracketed strings  (Read 1306 times)

Claude Lapalme

  • World Citizen
  • ***
  • Posts: 233

Since "Find and Replace" doesn't allow the use of wildcards, I wonder if expression language could do the following:

In the Artist field, I sometimes have instruments in parentheses such as:
Peregrine Took (nose flute); Lucy Honeychurch (piano); Sam I-am (ham trombone)

Is it possible to automate the removal of the bracketed items while keeping the semicolon to have:
Peregrine Took; Lucy Honeychurch; Sam I-am
as a result?

I can't seem to find a way ...
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Calling Expression Language experts - removing bracketed strings
« Reply #1 on: April 21, 2014, 12:05:26 pm »

It can be done with difficulty, because you have to manually code up the expression to handle some maximum number of replacements.

What is the max number of items that you have?

How many times will you be doing this operation?

Are you trying to create an expression field that does the removal?
Logged
The opinions I express represent my own folly.

Claude Lapalme

  • World Citizen
  • ***
  • Posts: 233
Re: Calling Expression Language experts - removing bracketed strings
« Reply #2 on: April 21, 2014, 12:40:48 pm »

Thanks for the reply, and I understand that I may dreaming ...

I was hoping to be able to plop it into the "Artist" field and hit enter, a bit like this brilliant one here to take the composer's first same and copy it to the beginning of the "Name" field:

=ifelse(!regex([Name], ^listitem([composer], 0, /,)), listitem([Composer], 0, /,):/ )[name]

A maximum would probably be 10 per track and it would be great if it worked on a selection of tracks.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Calling Expression Language experts - removing bracketed strings
« Reply #3 on: April 21, 2014, 01:08:42 pm »

MC lacks global substitution, so you have to do this manually by adding as many statements as you have items.  For example, this handles your three-item list.  Add more by duplicating the last ifelse line and incrementing the count/index numbers (in red):

listbuild(1, ;/ ,
ifelse(compare(listcount([comment]), >, 0), listitem(listitem([comment], 0), 0, / /()),
ifelse(compare(listcount([comment]), >, 1), listitem(listitem([comment], 1), 0, / /()),
ifelse(compare(listcount([comment]), >, 2), listitem(listitem([comment], 2), 0, / /())
)

One of the reasons I wrote pscriptor is that I wanted to provide a means to do this much more simply and powerfully.  The limitations in the MC expression language sometimes become too great.  This expression supplied to pscriptor does what you want for any number of items:

   s/ \([^)]+\)//g

Example output (data is in the Comment field):

   in(comment): 'Peregrine Took (nose flute); Lucy Honeychurch (piano); Sam I-am (ham trombone)'
   new(comment): 'Peregrine Took; Lucy Honeychurch; Sam I-am'
Logged
The opinions I express represent my own folly.

Claude Lapalme

  • World Citizen
  • ***
  • Posts: 233
Re: Calling Expression Language experts - removing bracketed strings
« Reply #4 on: April 21, 2014, 01:51:00 pm »

Thank you very much for your generous help. I will experiment with this information and learn a great deal at the same time!
Logged
Pages: [1]   Go Up