Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Using Flows
Answered

how to iterate through multiline text description field to extract text between known characters

(2) ShareShare
ReportReport
Posted on by 313
Hello,
 
I've made numerous attempts to no avail. I'm not sure if this is an Apply to Each or Do Until or using Indexes or something else.
I need to extract the string of text between known characters (which are US^string^US).
 
I am able to extract the first instance with the compose expression below.
 
How do I get the rest? And then, all the extracts into an array?
 
This is the multiline text description field that is set in the variable DescripContent.
 
****************************************************************
Description of the big job to be done:
 
US^The first big thing to do.^US
US^The second big thing to do after the first.^US
US^The third big thing to do that continues on another line,
more information about the third and final big thing.^US
 
More text here at the end.
****************************************************************
 
This is the compose expression that gets the first extracted string. Not sure if this is the best way to do it but it worked.
 
split(replace(split(variables('DescripContent'), 'US^')[1], '^US',''),'US^')
 
 
Appreciate the help as always!
 
 
  • Michael E. Gernaey Profile Picture
    40,272 Super User 2025 Season 1 on at
    how to iterate through multiline text description field to extract text between known characters
     
    So when you do a split it makes an array, you get one of these
     
    so if you have
     
    mmmm---HHHH and I did a split on ---
    i'd get an error of
    [0] = mmmm
    [1] = HHHH
     
    (an error)
    or
    1-Many results
     
    so in the split it creates an Array, and I want the first entry in the array and [0] gives that to me
  • Cgangweg01 Profile Picture
    313 on at
    how to iterate through multiline text description field to extract text between known characters
     
    Thank you so much for taking the time to provide this answer including the explanations. Every time I get a solution from the forum it boosts my abilities with the platform and helps with the various requirements and automation opportunities coming my way.
     
    For this expression the only thing I don't get is the zero in brackets at the end [0]. What is that doing?
     
    Split(Replace(trim(item()), decodeUriComponent('%0A'), ''), '^US')[0]
    Thanks again,
    Chris
  • Verified answer
    Michael E. Gernaey Profile Picture
    40,272 Super User 2025 Season 1 on at
    how to iterate through multiline text description field to extract text between known characters
     
    Assuming your ability to parse is always like this. here is what I did
     
    1. Manual trigger (just for your test)
    2. I created a variable called SampleText and pasted in your stuff
     
     
    3. Initialize an Array variable i called Lines starting at it being empty
     
    4. Added an Apply to each
    For the Data I put this
    split(string(variables('SampleText')), 'US^')
    again thats my variable, replace that with your variable/outputs
     
    I purposely split by only the Prefix US^ this time so I can loop through each returned row. This is because you have weird other stuff and I don't do regex ;)
     
    5. Add a Condition
    This condition is going to check if the current Item() of the apply to each contains ^US in it (which is your ending one) because it tells me I need to grab data from it. If it doesn't that means is the First, or Last lines which you dont want
     
    no tricks just item() and then the string '^US'
     
    6. Now in the Yes side you can technically just do one action but i always want to teach too so I did a compose and an Append to Array
    Split(Replace(trim(item()), decodeUriComponent('%0A'), ''), '^US')[0]
    In this one I am doing the following
    triming the spaces on the ends for the current item
    removing carriage return special characters
    then splitting by the End '^US'
     
    I do all of this because when splitting either your first row or your last row will be jacked up because both the real first line and last line are NOT the lines you ever want.
     
    7. Finally I use append to array, using the Output from Compose Get line details
    And when I run it, I have the following array which I show by adding a compose with the variable Lines 
     
    And now you can loop through those if you want.
     
    If this resolves  your issue I would appreciate if you would mark as Resolved and maybe a like :-)
    And it is
     
     
     and the whole thing looks like this

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 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,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,898 Most Valuable Professional

Leaderboard

Featured topics

Restore a deleted flow