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 / Extract Multiple occur...
Power Automate
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.

Categories:
I have the same question (0)
  • Ed Gonzales Profile Picture
    4,531 Most Valuable Professional on at

    @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

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 March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 592

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard