Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Unanswered

Extract Multiple occurances of text between characters in a String

(0) ShareShare
ReportReport
Posted on by 16

Hi,

 

I have a string that looks like this:

"Hello [contact.first], Blah Blah Blah [contact.dob] blah blah blah [contact.phone] bah blah."

 

If I wanted to grab every occurrence of [ ] and essentially loop through each, whats the best way to do it? There will always be one [ ] but they might be different and be different order etc.

 

I know I can get the contents between one occurrence but not sure how to get to each one.

 

Many thanks.

  • Ed Gonzales Profile Picture
    4,531 Most Valuable Professional on at
    Re: Extract Multiple occurances of text between characters in a String

    @stuax 

    Hey there -  So this isn't the prettiest, but it's what I got:

     

    What I did was replace all of the open brackets with something else like "[**" (you'll see why later).

    Then I replaced all of the close brackets with open brackets.

    Then, I did a split() on the open bracket.  This created an array with a bunch of junk, but the things I want to keep all start with "**".

     

    [
      "Hello ",
      "**contact.first",
      ", Blah Blah Blah ",
      "**contact.dob",
      " blah blah blah ",
      "**contact.phone",
      " bah blah"
    ]
     
    Here's the expression I used (replace the bold bit with your actual data):
     
    split(replace(replace(outputs('Compose'),'[','[**'),']','['),'[')
     
    To filter out the ** stuff, add a step "Filter Array", put the output from that expression as the Array, and then for the value, just put "item()" and change the operator to "Starts with" and then "**" (all without quotes) like this:
     
    20200511.PNG

     

    That output should be:
    [
      "**contact.first",
      "**contact.dob",
      "**contact.phone"
    ]
     
    And so then you can just do a Replace() to change the ** to nothing ('').
     
     
    If stuff is never in the same order, I'm not certain how you'll assign those values to actual fields, but I presume you've already worked that out.  
     
     
    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.

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1