Skip to main content

Notifications

Power Automate - General Discussion
Answered

Split text - capitalised phrase - split text with inbuilt conditions

(0) ShareShare
ReportReport
Posted on by 38

Hi all!

 

I am hoping someone can help me figure out this issue.  I want to be able to extract (split) text (event subject) that could look like any of the below: 

EXMAPLE 1: BLOGGS, Joe (Meeting - Office) 

EXMAPLE 2: BLOGGS, Joe, DOE, Jane (Meeting - Offsite)

EXMAPLE 3: SMITH, Timothy John, PHILLIP, Fairmont, GRACE Sally-Louise (Monthly Update - Richmond Office)

 

The results I ultimately want are:

function1: 

EXMAPLE 1: BLOGGS 

EXMAPLE 2: BLOGGS, DOE

EXMAPLE 3: SMITH, PHILLIP, GRACE 

function 2: 

EXMAPLE 1: Joe

EXMAPLE 2: Joe, Jane 

EXMAPLE 3: Timothy, Fairmont, Sally-Louise

 

I need the last name and first name in separate functions because they are used separately later on in the flow. 

 

Currently, I have a function that works for EXAMPLE 1 - 

Compose: split(triggerOutputs()?['body/subject'], ' ')[0]
which results in:    BLOGGS,
Compose: split(outputs('SURNAME_(with_comma)'), ',')[0]
which leaves me with:    BLOGGS
 
This works perfectly where there is only 1 name in the subject (as in EXAMPLE 1) .  However I can't figure out how to extract this if there is more than 1 name.
 
Ultimately my question is - is there a way to extract only the ENTIRELY capitalized words? and/or is there a way to extract the first word immediately after a comma (even where there are multiple commas, like in EXAMPLES 2 and 3) ? 
  • StillLearning_ Profile Picture
    StillLearning_ 38 on at
    Re: Split text - capitalised phrase - split text with inbuilt conditions

    perfect! Thank you!

  • Verified answer
    SamLed Profile Picture
    SamLed 2,326 on at
    Re: Split text - capitalised phrase - split text with inbuilt conditions

    Hi @StillLearning_ ,

     

    Okay, we have to clean input string of any comment in parentheses before because, as far as I know, we cannot do that using an expression, we need to use an Apply to each:

     

    SamLed_1-1707997730433.png

     

     

    This needs some explanations:

    • Apply to each take an array resulting of input string split by comma:  split(outputs('Compose'), ',')
    • For each item, we remove comment in parentheses if exists and remove any leading or trailing space with trim(): 
      if(contains(items('Apply_to_each'), '('), trim(substring(items('Apply_to_each'), 1, sub(indexOf(items('Apply_to_each'), '('), 1))), trim(items('Apply_to_each')))
    • Now, I use an advanced power automate trick to retrieve an array from "Apply to each" without using variable. I call outputs of compose belonging to Apply to each in the Filter action "From" property. Power Automate won't propose it in dynamic contents, you'll have to write it manually in expression: 
      split(join(outputs('Remove_comments_in_parentheses'), ' '), ' ')
    • Then use the required expression to extract capitalized names or not ones
    • Last action convert output array into string using join()

    Results:

    SamLed_3-1707998486723.png

    ______________________________________________________________

    If I have answered your question, please Accept the post as solution.
    If you like my response, please Thumbs Up.

     

  • StillLearning_ Profile Picture
    StillLearning_ 38 on at
    Re: Split text - capitalised phrase - split text with inbuilt conditions

    it works! the only issue is that in EXAMPLE 3 ("SMITH, Timothy John, PHILLIP, Fairmont, GRACE Sally-Louise (Monthly Update - Richmond Office)") I end up with the words in-between the parentheses (Update & Richmond), as below. 

     

    Nonetheless, you have been a huge help!! thank you so much !

     

    StillLearning__0-1707961001953.png

     

     

     

  • SamLed Profile Picture
    SamLed 2,326 on at
    Re: Split text - capitalised phrase - split text with inbuilt conditions

    Hi @StillLearning_,

     

    My bad, so sorry, just figured out I made a bad copy/paste of the expression, corrected it in my initial answer, was missing 2 right parenthesis at the end.

     

    it is: @and(and(not(equals(item(), toUpper(item()))), greater(length(item()), 1)), and(not(contains(item(), '(')),not(contains(item(), ')'))))

    ______________________________________________________________

    If I have answered your question, please Accept the post as solution.
    If you like my response, please Thumbs Up.

  • StillLearning_ Profile Picture
    StillLearning_ 38 on at
    Re: Split text - capitalised phrase - split text with inbuilt conditions

    okay I have no idea what I am doing wrong now. I have added the 2 parentheses in the locations noted above and now I am getting a different error - 

     

    StillLearning__1-1707957262481.png

     

    StillLearning__2-1707957275660.png

     

  • SamLed Profile Picture
    SamLed 2,326 on at
    Re: Split text - capitalised phrase - split text with inbuilt conditions

    Lacks also one ")" at the end, I think 

    SamLed_1-1707956746621.png

     

  • SamLed Profile Picture
    SamLed 2,326 on at
    Re: Split text - capitalised phrase - split text with inbuilt conditions

    Don't worry, I'm glad to help 😉

     

    in your sceenshot, I highlighted where it lacks a "(":

    SamLed_0-1707956638745.png

    ______________________________________________________________

    If I have answered your question, please Accept the post as solution.
    If you like my response, please Thumbs Up.

     

  • StillLearning_ Profile Picture
    StillLearning_ 38 on at
    Re: Split text - capitalised phrase - split text with inbuilt conditions

    Sorry please forgive my ignorance (you have been so helpful!) -  what is it I am missing ? 

    This is what i am trying, but it is giving me the above 'invalid' result.. 

     

    From:  split(replace(outputs('Compose'), ',',''), ' ')

    Expression@And(and(not(equals(item(), toUpper(item()))), greater(length(item()), 1)), and(not(contains(item(), '(')),not(contains(item(), ')'))

     

     

  • SamLed Profile Picture
    SamLed 2,326 on at
    Re: Split text - capitalised phrase - split text with inbuilt conditions

    That's the filter expression which is failing not the from one, it lacks a parenthesis between the 2 first and 😉

    ______________________________________________________________

    If I have answered your question, please Accept the post as solution.
    If you like my response, please Thumbs Up.

  • StillLearning_ Profile Picture
    StillLearning_ 38 on at
    Re: Split text - capitalised phrase - split text with inbuilt conditions

    I have tried this expression - with the same "from" formula:

    split(replace(outputs('Compose'), ',',''), ' ')  -  but it is telling me it is invalid ..

     

    StillLearning__1-1707954602801.png

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,508

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,839

Leaderboard