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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Need to Extract Specif...
Power Automate
Answered

Need to Extract Specific Text from Email Body

(0) ShareShare
ReportReport
Posted on by 83

How would I extract the word "FIRST" from the following example text (which is already a variable I've created)?

 

"You have a new notification

Hello,


A note on FIRST LAST had its reminder triggered."

 

 

Categories:
I have the same question (0)
  • eliotcole Profile Picture
    4,390 Moderator on at

    If you just wish fo the literal word to be removed, then when you define the variable you could wrap a replace() function around whatever is being done to create that. Thereby using:

     

    replace(INPUT_STRING, 'FIRST ', '')

     

    To replace "FIRST " with "" (nothing).

  • dedgerton1 Profile Picture
    83 on at

    No, I need that word to use elsewhere in my Flow. Obviously it’s a name, so the length will vary. 

  • eliotcole Profile Picture
    4,390 Moderator on at

    I see, are these names defined anywhere else in the flow as variables or in data somewhere?

     

    As a quick aside; it would really help if you edit in as much of the flow (obfuscating private details) in your original question above. This way we can have more context of what is needed and what we can do to help.

     

    Suffice to say, broadly speaking, there's a solution with the new slice() function:

    1. Initialise three variables:
      1. Two variables for the first and last name.
      2. One for them both as a phrase.
    2. Within the logic of the flow define those variables however you need to (initially, repeatedly, etc).
    3. Use two slice() functions to bridge the text back where needed.

     

    Essentially either side of the first name is defined by a slice() function with a space inbetween.

     

    Within each slice you will use the position of the full name to identify where to stop the first slice, and (with the length of the first name added in) start the second slice.

     

    You can run those as two separate expressions, or you can put them all in a concat().

     

    I'll edit in a very basic example of this, but it goes without saying that it doesn't have any of the logic you will likely have in your flow.

     

    flowy basic.jpg

     

    Result

    flowy.jpg

     

    With concat()

    flowy harder.jpg

     

    fullNameWesternVAR has a space between the other two names.

     

    Then you either use two splices either side of a space, the first being:

    trim(slice(outputs('input'), 0, indexOf(outputs('input'), variables('fullNameWesternVAR'))))

    Using the FULL name to find the position both times, including the second, after said space, here:

    trim(slice(outputs('input'), add(add(length(variables('givenNameVAR')), indexOf(outputs('input'), variables('fullNameWesternVAR'))), 1)))

    Here you've added an extra character to account for the zero start.

     

    Those come together in one concat() as:

    concat(trim(slice(outputs('input'), 0, indexOf(outputs('input'), variables('fullNameWesternVAR')))), ' ', trim(slice(outputs('input'), add(add(length(variables('givenNameVAR')), indexOf(outputs('input'), variables('fullNameWesternVAR'))), 1))))
  • dedgerton1 Profile Picture
    83 on at

    Thanks. Mobile at the moment. I’ll upload examples later. I can say that the text on both sides of the FIRST and LAST names will always be the same. Just need the first name.

  • eliotcole Profile Picture
    4,390 Moderator on at

    Aye, all good, @dedgerton1 , matey.

     

    For what it's worth, the method that I've given above allows that text to not be an issue (in case templates change elsewhere).

     

    Just subsume it all into your logic however you need.

  • dedgerton1 Profile Picture
    83 on at

    Here's what I'm working with. Looking to use that FIRST name in an outgoing email. Although, I think I can reverse-engineer your suggestion to use the given name instead. Right?

     

    Screen Shot 2022-05-10 at 8.50.38 PM.png

  • Verified answer
    eliotcole Profile Picture
    4,390 Moderator on at

    OK, thanks for that! 🙂

     

    Assuming that's all you get, then, yes, you could reverse engineer it.

     

    I'm unclear where you'd get their email address from, is that split that you use there taking that information from somewhere else in the email?

     

    I only ask because if that email is Rich Text (HTML) then there's a high liklihood that the name(s) have a hidden piece of code that differentiates it/them from the rest of the email.

     

    If you use Body (the capital 'B' is important, but small 'b' could be even *more* useful), instead of Body Preview, it provides the email's HTML, too. (if you like you can PM that to me)

     

    Using that you might have more usable information to work with, otherwise, yes, just use this to get the first name:

     

     

     

    trim(
     first(
     split(
     first(
     skip(
     split(
     triggerOutputs()?['body/bodyPreview'], 
     'A note on '
     ), 
     1
     )
     ), 
     ' '
     )
     )
    )

     

     

     

    That will basically do what you need it to do.

     

    I've plotted that out so you can see it all in action, but it can all be one line, too.

     

    It will:

    1. split() ... split on "A note on " in the plain text of Body Preview,
    2. skip() ... skip the first entry in the resultant array,
    3. first() ... extract the string of the first entry in the new array,
    4. split() ... split that text on spaces,
    5. first() ... extract the string of the first entry in the resultant array,
    6. trim() ... then take any extra spaces from the start or end of that text.

    If you put notes in the actions, and/or comments in the flow, then you will be able to come back to this in the future and understand what's going on more easily, too.

    ---

    EDIT

    I would say, though, that you would be wise to set up some more around this, otherwise it will create flow runs on every email that you get. Things like:

    1. Limit the flow to only check emails from the sender that sends it.
    2. Set a rule in outlook to mark these emails with a particular 'Importance' level.
    3. If it does run, perform certain actions dependent on its categories (based on Outlook Rules).
    4. Set trigger conditions to further restrict whether it even triggers.

    #1 will likely be the most important to use here, because it will drastically reduce the amount of flow runs that this causes. However, #2 will also really assist on lessening the amount of flow runs this produces, as will #4 but that is more advanced stuff.

     

    Looking at #3, this will likely become important if the service or app that you are using produces alerts to you for more than just these reminders. For example, the reminders might be one notification, but you also receive notifications from the app/service when an event is moved.

     

    Using that example, I'd then make two Outlook categories 'thisApp-reminderNotification' and 'thisApp-eventMoved', to differentiate between the two. But you also apply the category 'thisApp', and re-use 'reminder' and 'eventMoved' categories for various emails.

     

    Anyway, in my example flow below I've got a category 'thisApp-reminderNotification' applying to all alerts from 'notifications@thisapp.com'.

     

    Main Flow DetailMain Flow Detail

     

    Apply to each category on the emailApply to each category on the email

     

  • dedgerton1 Profile Picture
    83 on at

    I'm receiving this error even when I correct the variable name (BodyPreview):

     

    Unable to process template language expressions in action 'First_Name' inputs at line '0' and column '0': 'The template language function 'split' expects its first parameter to be of type string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#split for usage details.'.

     

    Screen Shot 2022-05-11 at 11.07.33 AM.png

     

  • dedgerton1 Profile Picture
    83 on at

    Disregard. I got it! Thanks again!

  • eliotcole Profile Picture
    4,390 Moderator on at

    Oh, nice ... glad you're sorted, mate. Enjoy!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 791

#2
Valantis Profile Picture

Valantis 582

#3
Haque Profile Picture

Haque 529

Last 30 days Overall leaderboard