Please help me with a RegEx to extract only the numbers from a string variable

Hi, I have a string variable which contains both text and numbers assigned to a string variable. I want to extract the numbers from the string using RegEx.

Example: If the text is “Text#$1234”, I want to extract “1234” alone

Thanks

1 Like

Hi @JeevaSadha , can you try this?

\d+

  1. Add a “Matches” action.
  2. Set the input text to “Text123”.
  3. Set the regex pattern to \d+.
  4. In the properties panel, set the “Result” field to a variable (e.g., extractedDigits).

This should extract the digits alone.

Thanks,
Aswin Sridhar

1 Like

Hi @JeevaSadha

Try this:

Assign-> Input = "Text#$1234"

Assign-> Output= System.Text.RegularExpressions.Regex.Match(Input,"[0-9]+").Value.Trim()

Hope it helps

1 Like

Hi @JeevaSadha

(?<=\$)(\d+)

Regards

1 Like

Hi, I’m able to assign it to a variable and extract digits alone. But, is there any other way we could extract all the digits like for example: if my text is qwerty1234uioo5678. I’d need the output to be “12345678”. However, I can iterate through matches but It would be helpful if I can get a regex to extract all numbers.

Thanks for your response

Hi
Input:-
image

Output:-
image

xaml File:-
Regex to get only numbers forum.zip (2.9 KB)

If this works for you, please mark this as a solution for others reference.

Thanks

Hi @JeevaSadha

Please check below:

String.Join("",System.Text.RegularExpressions.Regex.Matches(input.ToString,"(\d+)"))

Regards

1 Like

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