How to extract integer from text

Hi Team,

Please help me on below issue,

Extract 78.89 number from list —> Extract 78.89
Team size is 80 number. ----> Team size is 80
Sandeep team number is 79 lastly. ----> Sandeep team number is 79

Team, i want highlighted part(how to remove right side part upto integer value) which expression should i use for this?

HI @Smitesh_Aher2

Please use the below regex:

(?<=\d+\.?\d*\s+)(.*)

Regards

Can you please send expression ss?

Hi @Smitesh_Aher2

Please check the below :


System.Text.RegularExpressions.Regex.Match(Input,"(.*\d+\.?\d*)").Value

System.Text.RegularExpressions.Regex.Match(Input,"(?<=\d+\.?\d*\s+)(.*)").Value

@Smitesh_Aher2

System.Text.RegularExpressions.Regex.Match(Input,".*[a-z]+\s*\d+\.?\d*").Value

Hey @Smitesh_Aher2
you can use Regex expression:
extractedNumber = System.Text.RegularExpressions.Regex.Match(inputString, "\d+(\.\d+)?").Value

Hi @Smitesh_Aher2

Do you wanted to remove the highlighted part?
image

Or else the non highlighted part?

Regards

Hi @Smitesh_Aher2

Use below Regex Expression

(.*\d+\.?\d*)

Hope it will helps you :slight_smile:

Hi @Smitesh_Aher2

Please check the below workflow:

Input= "Extract 78.89 number from list
Team size is 80 number.
Sandeep team number is 79 lastly."

Output= System.Text.RegularExpressions.Regex.Replace(Input,"(?<=\d+\.?\d*\s+)(.*)","")

Input= "Extract 78.89 number from list
Team size is 80 number.
Sandeep team number is 79 lastly."

Output= System.Text.RegularExpressions.Regex.Replace(Input,"(.*\d+\.?\d*)","")

Regards

Hi Team,

Thanks for response.

Extract 78.89 number 2 from list —> 78.89
Team size is 80 number. ----> 80
Sandeep team number is 79 lastly. ----> 79

How to get highlighted part? which expression should i use?
I want integer value which are present at start of text.

1 Like

Hi @Smitesh_Aher2

simply use the below:

\d+\.?\d*

HI @Smitesh_Aher2

Input= "Extract 78.89 number from list
Team size is 80 number.
Sandeep team number is 79 lastly."

Output= System.Text.RegularExpressions.Regex.Matches(Input,"\d+\.?\d*")

String.Join(Environment.NewLine, Output.Cast(Of Match)().Select(Function(m) m.Value.Trim()))

Regards

Hi @vrdabberu

What will be output in the below case? i want highlighted value.

Extract 78.89 number 2 from list

What is variable type of input?

HI @Smitesh_Aher2

Please use the below workflow:

Input = "Extract 78.89 number 2 from list
Team size is 80 number.
Sandeep team number is 79 lastly."


Output= System.Text.RegularExpressions.Regex.Matches(Input,"[A-Za-z]+.*")
For Each currentItem in Output
                Write Line-> System.Text.RegularExpressions.Regex.Match(currentItem.ToString,"\d+\.?\d*").Value
End For Each

Sequence7.xaml (9.3 KB)
MicrosoftTeams-image (3)

Regards

Thanks @vrdabberu i got value as expected…

Extract 1 04.4 number 2 from list —> i am getting output as 1.

There is whitespace present after 1. Which expression use for to get value = 1 04.4 ?

Hi @Smitesh_Aher2

Please use the updated regex:


Input = "Extract 78.89 number 2 from list
Team size is 80 number.
Sandeep team number is 79 lastly."


Output= System.Text.RegularExpressions.Regex.Matches(Input,"[A-Za-z]+.*")
For Each currentItem in Output
                Write Line-> System.Text.RegularExpressions.Regex.Match(currentItem.ToString,"\d+\s?\d*[.,]?\d*[.,]?\d*").Value.ToString.Replace(" ","")
End For Each

Sequence7.xaml (9.4 KB)

Regards

Thanks @vrdabberu and team for giving me correct solution.

1 Like

You’re welcome @Smitesh_Aher2

Happy Automation !!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.