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

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Help needed to extract substring with variable length

(0) ShareShare
ReportReport
Posted on by 48

Hello masters,

 

I am totally new to Microsoft Flow and I have been trying my luck to get started with it to complete a sample task automatically.  I have sent an bulk email to all my customers requesting them to register for the webinar.  Once they register I get an automated email from system in html format.  I am trying to build a flow to get their details and put it in a excel online list which is stored on my onedrive for business. 

 

  1. Trigger and Data Connections worked well.  
  2. I also managed to convert the email body to text from its original html format using Html_to_text step.
  3. I managed to store that converted plain text into a variable called 'EmailBody'

From the above step onwards the issues starts, I have got an information in following format:

 

Webinar registration (webinar_reg-bah)

Company : <Customer Business Name>

Name: <Customer Full Name>

Email: xxxx@xxx.xxx.xx

phone: xxxxxxxx

position: <Designation>

 

I need help to extract the exact information from above and put it in the appropriate columns in the excel table.  Since I do not know exact length of strings I am unable to define it in any numeral form.

 

Any help on the above issue is highly appreciated.

 

Thank you

 

Kedar

I have the same question (0)
  • Pstork1 Profile Picture
    68,295 Most Valuable Professional on at
    Re: Help needed to extract substring with variable length

    In PowerApps I've done this kind of thing using Match() and a REGEX expression.  But Flow doesn't have a REGEX expression at this point.  So the next best thing is to use IndexOf to find where the Labels are in each line.  Then use Substring and the differences between each label to extract the text that falls between the end of one label like 'Name:' and the beginning of the next like 'Email:'

  • kedarsk Profile Picture
    48 on at
    Re: Help needed to extract substring with variable length
    Hello sir

    Whatever you mentioned May be that is the right solution but i need sample code. Because as i mentioned i am totally new to flow and do not know anything about expressions in flow.

    Hence it would be great if you can provide me sample code.
  • v-litu-msft Profile Picture
    on at
    Re: Help needed to extract substring with variable length

    Hi @kedarsk,

     

    Maybe this post could help you something:

    https://powerusers.microsoft.com/t5/Building-Flows/Extract-text-from-Body-of-an-email-in-Flow/m-p/51548 

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • kedarsk Profile Picture
    48 on at
    Re: Help needed to extract substring with variable length

    Hello support team

     

    Thank you for the link.  However, that did not answer my question either.  I could see in that link some of the examples but all of them had the indexOf parameter define by numbers.  In my case, I do not know at which position it will be exactly hence I need to figure it out dynamically.

     

    Further as I mentioned in all my posts.  I am a total new to Microsoft Flow concepts.  Therefore, I have prior little experience of PowerShell scripting and Excel Formulas with VBA.  Beyond this my understanding about programming is at very basic level.

     

    Hence, appreciate if someone can provide me some visual / spoon fed techniques to achieve my goal and encourage my interest in learning more about Flows.

     

    Thank you

  • Verified answer
    Pstork1 Profile Picture
    68,295 Most Valuable Professional on at
    Re: Help needed to extract substring with variable length

    AS an example, here are the formulas to extract the Company Name. Each one goes in its own variable or Compose action.

    //Returns the starting position of the Company Name
    add(indexOf(variables('InputText'),'Company :'),9)
    
    //Returns the length of the Company name
    sub(indexOf(variables('InputText'),'Name:'),outputs('Compose'))
    
    //extracts and trims the company name from the overall text.
    trim(substring(variables('InputText'),outputs('Compose'),outputs('Compose_2')))

     

  • kedarsk Profile Picture
    48 on at
    Re: Help needed to extract substring with variable length

    Hi @Pstork1 

     

    You are awesome man!  The solution worked for me initially.  I appreciate for your detailed explanation by comments which helped me to understand the flow of the proposed solution.  However, to mark it as accepted solution, I just need following information:

    1. I noticed that you have put number 9 which is the length of  'Company : '.   However, can we calculate it dynamically instead of manually putting 9?
    2. If we do it this way then, I will have to write the same lines of code for each and every detail that I want to extract from email so I might end up writing this code for 7-8 times since there are that many details.  Can we use looping instead of manually writing down this code?
    3. The code will work fine until the last line however it will fail at the last line as we are calculating the starting position of the first field and then subtracting that number from the start position of another field.  In this example for field on the last line there will not be any other line to subtract the value from.

    Appreciate your clarification on the above.

     

    Regards

    Kedar

  • Verified answer
    Pstork1 Profile Picture
    68,295 Most Valuable Professional on at
    Re: Help needed to extract substring with variable length

    1) use this instead

    add(indexOf(variables('InputText'),'Company :'),length('Company :'))

    2) You could probably figure out a way to use looping.  But then you have to also figure out how to change the pattern being searched for in each loop iteration.

    3) For the last line simply use the length of the total string in place of the lastIndex of the next label.  The numbers change, but the pattern is the same.  Look for what you know precedes and follows the string and then use that to figure out dynamically where each string starts and stops. 

  • kedarsk Profile Picture
    48 on at
    Re: Help needed to extract substring with variable length
    Hello brother

    Can you please help me for looping code? Also i had a question about how will it be if we can store it in an Array instead of using normal compose action? I think with array we can use loops.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 659 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 386 Moderator

#3
chiaraalina Profile Picture

chiaraalina 290

Last 30 days Overall leaderboard