How to extract a number from a particular string

Hi team,

How to extract only number present in the text .
And the text may vary.

Regards,
Bhagyashree

@Bhagyashree_S

Please put the input and output samples

@Bhagyashree_S

If the number does not have points or comma use \d+

If it has points \d+\.\d+

If it has comma also then [\d,]*\.\d+

Cheers

How to use regular expression…we need to pass it on assign activities right?

@Bhagyashree_S

You can use matches activity or use assign as below

Requirenumberstring = System.Text.RegularExpressions.Regex.Match(InputStringVariable,"\d+").Value

Cheers

@Bhagyashree_S

StrOutput=System.Text.RegularExpressions.Regex.Match(currentItem.ToString,"[\d\,]*\d+\.?\d*").Value

Hi @Bhagyashree_S

You can try the below syntax:

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

Hope it helps!!

Hi @Bhagyashree_S

Try to extract with the Regular expressions, Check the simple below expression,

[\d\,?\.?]+

You can check in the regexr.com
image

For Example -

- Assign -> Input = "For the Meeting 8,750 memebers attended"

- Assign -> Output = System.Text.RegularExpressions.Regex.Match(Input.ToString,"[\d\,?\.?]+").Value

Check the below workflow for better understanding,

Hope it helps!!

Hi @Bhagyashree_S

Can you try the below

InputString="Hello world! 1234 How are you?"
Output=New String(InputString.Where(Function(c) Char.IsDigit(c)).ToArray())

Cheers!!

Thank you so much …it worked :blush:

1 Like

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