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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Extract the first integer
Power Automate
Suggested Answer

Extract the first integer

(0) ShareShare
ReportReport
Posted on by 18
 
Hi, 
 
I am creating a record in a list from a form. 
 
The input from the form is a string and the input in the list should be a number. 
 
Occassionally, someone would put a integer and then provide a text string (with or without integer in it). ex. 100 with 50 A and 50 B
 
I could not find a viable solution to extract the first integer from this string. From the example, I only want the 100, not other integers nor text. 
 
Copilot suggested:
int(replace(variables('@{variables('Noinstructutor')}'), 'a', ''))
and 
int(first(match(variables('YourTextVariable'), '\d+')))
but neither works. 
 
I found this: https://tachytelic.net/2021/02/power-automate-extract-numbers-from-string/ but it looks like it would take all the integers from the original string to get a new one. 
 
Can someone help me with this issue? 
 
Thanks,
Rita
Categories:
I have the same question (0)
  • Suggested answer
    Sarah Guest 20 Profile Picture
    27 on at
    Hi Rita, 
     
    Will the integer that you want to extract always be at the start of the string followed by a space? If so then you could split the string by spaces and then pick the first part from the split array. 
     
    first(split(triggerBody()?['yourFormField'], ' '))
     
    Also I am not sure if it is possible to make changes to the form where the users are inputting their answers so they can only enter an integer value. 
     
    Hope this helps but if not maybe give more examples of what the text strings could be. 
  • RitaHL Profile Picture
    18 on at
    Thanks to both @Sarah Guest 20 and @AlexEncodian. Both methods worked for this special case. I might be able to use Utility for free if not many people use this form.  
     
    @Sarah Guest 20 I think most of the times people would use a space before typing anything else that follows the number. However, maybe they would also use "(" or just directly follow the number with text. Is there a way I can make the expression more flexible? 
     
    I think if I created a form directly from the list, the form might collect the pertinent data type. However, I had to create a form from MS form directly to use the multilingual version. In the MS form platform, there is very little I can do re. limiting the input (I also tried using rating but it only allows 1-10):
  • Suggested answer
    David_MA Profile Picture
    12,982 Super User 2025 Season 2 on at
    Looks like there is a few other solutions, but I will post this option as well:
     
     
    1. The first variable is the string value from your form named string: 100 with 50 A and 50 B
    2. The next variable, String Array, splits it on the spaces with this expression: split(variables('String'), ' ')
    3. The third variable is a Boolean named NumFound and is set to false
    4. The fourth variable, Number, is an integer variable with no default value
    5. Pass the Array variable through the Parse JSON with this scheme: { "type": "array""items": { "type": "string"  } }
    6. The condition uses the following:
      1. The top condition uses this expression: isInt(items('Apply_to_each'))
      2. The bottom condition is the variable NumFound
    7. On the true side, set NumFound to true
    8. And then set the Number variable using this expression: if(variables('NumFound'), int(items('Apply_to_each')), null)
    It returns the first integer found from the string:
     
    If any or all of these answered your question, please mark them as such.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard