web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Parse string from Emai...
Power Automate
Unanswered

Parse string from Email subject between two points

(0) ShareShare
ReportReport
Posted on by 286

Hello,

         I'm having a little trouble with what the right expression is to grab a string from between two points in an email subject.

The Subject of the emails that i have coming in are as follows as an example

"New Email (Text Word) has come in"

 

What i am trying to do is grab the string between ( and ) 

I have this as the expression but it keeps failing stating that the length cannot be negative. 

substring(triggerbody()?['Subject'],add(indexOf(triggerbody()?['Subject'],'('),1),sub(lastIndexOf(triggerbody()?['Subject'],')'),add(indexOf(triggerbody()?['Subject'],')'),1)))

I have had a look at some of the other posts that talk about parsing text from an email subject but i couldnt get those suggestions to work for me.

Can someone tell me what i am doing wrong in my expression.

Categories:
I have the same question (0)
  • Verified answer
    stephenJames Profile Picture
    286 on at

    I found the error in my expression i had a ) where i should have had a (

    Heres the correct expression that is working

     

    substring(triggerbody()?['Subject'],add(indexOf(triggerbody()?['Subject'],'('),1),sub(lastIndexOf(triggerbody()?['Subject'],')'),add(indexOf(triggerbody()?['Subject'],'('),1)))
  • Verified answer
    Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    You might try spliting the string on the '(' and ')' something like this

    First(split(last(split(triggerbody()?['Subject'],'(')),')'))
  • stephenJames Profile Picture
    286 on at

    @Pstork1 wrote:

    You might try spliting the string on the '(' and ')' something like this

    First(split(last(split(triggerbody()?['Subject'],'(')),')'))

    Thanks @Pstork1 that seems to be a much simpler solution. 

  • jslsmithyx Profile Picture
    97 on at

    Hi @Pstork1

     

    Sorry to come back to an old thread. I'm trying to achieve pretty much the same setup, however I am trying to use a previous 'Initialise Variable' step in the flow as the reference point in the next 'Initialise Variable', where the email subject will be broken off. I basically require the last string of an email subject broken off, starting with the 8th word in the string, ending with up to the 20th word in the string. 

     

    This is the expression I am currently having issues with: 

    first(split(last(split(triggerbody(variables('CR Number'))?['Subject'],'CR Number')),')'))
     
    & this is the error I'm currently receiving: Unable to process template language expressions in action 'Initialize_variable_4' inputs at line '1' and column '2799': 'The template language function 'triggerbody' must not have any parameters.'.
     
    Any help would be greatly appreciated!! 
     
    Thanks, 
     
    Joe 

     

  • Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    Build out your formula using the Dynamic Content tab and the Expressions Tab.  You will find that the Variables object is addressable on its own without using TriggerBody().  That's why you are getting the error.  Just start your formula on the expressions tab and then click back to the Dynamic Content tab when you need to add a specific piece of content  You can go back and forth several times.

  • jslsmithyx Profile Picture
    97 on at

    Thanks for the reply. 

     

    I came up with this using the method you advised & its doing the trick: 

     

    last(split(triggerBody()?['subject'], variables('CR Number')))
     
    Thanks for your help. 
     
    Joe
  • Joe1203 Profile Picture
    2 on at

    Hi Stephen,

    Do you have any idea how to get more than one ( )? For example, the subject on email is 123(45)78(9). How do I get (45) and (9) at one time? Thanks 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard