Hello - fairly new to Microsoft Flow and loving it.
Looking to see if there is a way to get the first instance of a text from the body of an email. I have Initialized a variable called EmailBody with the type String, and the value as the body of the microsoft email.
So the HTML of the email may look like
"<tr><td class="fieldTitle"><label>Product:</label></td><td class="fieldData"><label>Carrots</label></td></tr>"
"<tr><td class="fieldTitle"><label>Product:</label></td><td class="fieldData"><label>Apples</label></td></tr>"
I want to get the first instance of Product: and store the variable Carrots
To do this what I have been doing is splitting the EmailBody variable, and used the last part of it. I guess the hard part is that it splits the last instance - in this case the last instance of "Product: ". But what do I use for the expression if I want to get the first instance of "Product: "
Initialize Variable
Name: ProductValueStep1
Type: String
Value (expression) = last(split(variables('EmailBody'),'Product: '))
Initialize Variable
Name: ProductValue
Type: String
Value (expression) = first(split(variables('ProductValueStep1'),'</label>'))
So, an interesting way to go about this...but it's a fun approach. Here's something that might help:
When you use split(), it takes a string and creates an array based on the delimiter you choose.
You can select specific elements of an array by adding the element number at the end (keep in mind it starts at zero). So if you had the text:
"<tr><td class="fieldTitle"><label>Product:</label></td><td class="fieldData"><label>Carrots</label></td></tr>"
And you use the expression:
split(variables('EmailBody'),'Product: ') then you will end up with two elements, everything before the delimiter ("Product: "), and everything after:
Element 0 would be: <tr><td class="fieldTitle"><label>
Element 1 would be: </label></td><td class="fieldData"><label>Carrots</label></td></tr>
Maybe try splitting on the '<label>' and then taking the3rd element: split(variables('EmailBody'),'<label>') would give these results:
Element 0: <tr><td class="fieldTitle">
Element 1: Product:</label></td><td class="fieldData">
Element 2: Carrots</label></td></tr>
So, split(variables('EmailBody'),'<label>')[2] would give you Carrots</label></td></tr>
Then, split that again on '</label>' and take the first part: split(split(variables('EmailBody'),'<label>')[2],'</label>')[0] should give you just "Carrots" (No quotes). Here's a video on split:
Keep us posted.
-Ed
If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.
Michael E. Gernaey
497
Super User 2025 Season 1
David_MA
436
Super User 2025 Season 1
Riyaz_riz11
244
Super User 2025 Season 1