Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

SPlit string from email subject to extract specific text

Like (0) ShareShare
ReportReport
Posted on 28 Aug 2021 00:22:08 by 43

Hi All,

 

I've been struggling to extract varied specific text contained within this email subject: 

 

Plan completed for Site title: Test Site | Org: BBC | Site Type: Team | Form Status: Complete form | SRS: OFFICIAL - Team or Group | MyIQ_No: 1000A|| 

 

variable 1  = need to extract  and assign it:  1000A

variable 2  = need to extract  and assign it: Test Site

variable 3  = need to extract  and assign i:  OFFICIAL - Team or Group

 

etc

 

tried these variations and they don't work:

 

last(split(first(split(triggerBody()?'subject','||')),'MyIQ_No: '))

last(split(first(split(triggerBody()?['subject'],'||')),'MyIQ_No: '))

 

Please kindly help?

Thanks in advance

 

SKooLZ

  • SkoolZ Profile Picture
    43 on 03 Sep 2021 at 12:11:16
    Re: SPlit string from email subject to extract specific text

    Thank you all for generous replies to my query, much appreciated! I only managed to test and implement Eliotcole's solution as it was simpler for me to follow and apply and it worked a charm. So the other solutions may work similarly but I didn't test them but thank you all again for your kind assistance with this!!

  • eliotcole Profile Picture
    4,218 Super User 2025 Season 1 on 28 Aug 2021 at 13:12:39
    Re: SPlit string from email subject to extract specific text

    If you can confirm that the subject line will always be formatted that way, but might contain new fields, then this is a bit more complicated, but will put it all in a JSON object, and you won't be at the mercy of whatever is creating that email subject maybe changing the field names.

     

    As always, though, remember that when working with text strings you are always at the mercy of the string formatting.

     

    1. Create an Object variable, I've called it subjectFieldsVAR.
    2. Place the following expression in the input field:
    setProperty(json(replace(replace(replace(replace(variables('emailSubjectVAR'), 'Plan completed for ', '{"planStatus":"empty","'), ' | ', '","'), ': ', '": "'), '||', '"}')), 'planStatus', first(skip(split(variables('emailSubjectVAR'), ' '), 1)))

    This does a few things;

    1. Replace for Structure - Using multiple replace() functions it roughly formats the text into a JSON object
    2. Replacing for New Field - It also uses the replace() function to add an extra field called "planStatus",
    3. Formatting to JSON - It then uses a json() function to changes it from string text to JSON data,
    4. Setting the New Field - Finally it uses setProperty() to change the value of "planStatus" to whatever the status of the plan was.

    Here's the imagery:

    objectionable.jpg

     

  • Verified answer
    eliotcole Profile Picture
    4,218 Super User 2025 Season 1 on 28 Aug 2021 at 12:17:05
    Re: SPlit string from email subject to extract specific text

    To differ from Eric's excellent solution only slightly, I would split on the actual words, then you can save the Apply to each action.

    1. Create 3 string variables:
      • myIqNoVAR
      • siteTitleVAR
      • srsVAR
    2. In each variable place the following expression, where EMAIL_SUBJECT is your email subject dynamic data, and FIELD_NAME is the text that you want to split on:

     

    trim(first(split(last(split(EMAIL_SUBJECT, 'FIELD_NAME')), '|')))

     

    In my example, below, you can see I had to assume that my input was a variable called emailSubjectVAR, you can either use that or simply place the email subject there using the dynamic data instead of the variable.

    00 - full flow.jpg

     

    All that expression is doing is:

    1. split(); on on the FIELD_NAME that you want in the EMAIL_SUBJECT.
    2. last(); to take the second (last) item from the array of 2 items that it makes to get the value.
    3. split(); again on the '|' to get rid of the rest of the text.
    4. first(); to take only the first of the many items that could make.
    5. trim(); to remove any spaces around the text.
  • eric-cheng Profile Picture
    5,171 on 28 Aug 2021 at 00:50:30
    Re: SPlit string from email subject to extract specific text

    Hi @SkoolZ ,

     

    You can try a normal split(xxx, '|') into an array, loop through the array and if the value contains MyIQ_No, save to a variable and repeat for all your values.  You can also reference the index of the array if you dont want to loop.

     

    Screenshot_20210828-104832_Chrome.jpg

     

    Screenshot_20210828-104751_Chrome.jpg

     

    --------------------------------------------------------------------------
    If I have answered your question, please mark my post as a solution
    If you have found my response helpful, please give it a thumbs up

    Connect on LinkedIn

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,731 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,075 Most Valuable Professional

Leaderboard
Loading started