Regex for 5 digits from longer string

Hi,

example of my string

1234 test TEST 1234567

from here I need to get 5 digits. Normally the second number has 5 digits, but it happenes that is has more. Then I would need to get first 5 digits from it.

Can you help me here?

grafik

Hi @camaro123

Check the below assign syntax:

Input = "1234 test TEST 1234567"

Output = System.Text.RegularExpressions.Regex.Match(Input,"\b\d{5}").Value.Trim()

image

Hope it helps!!

@camaro123

\d{5} should dot he job

Cheers

Hey @camaro123

Take a look here for some more information on Regex

Cheers

Steve

Hi @camaro123

Please try using the regex to extract the data.

Regex

\b\d{5}

\b - represent the boundary of the text
\d - represent the number format in regex
\d{5} - represent the 5 number to get conjugative
\b\d{5} - represent get only the boundary of the 5 digit number.

UiPath Code using Assign Activity:

number = System.Text.RegularExpressions.Regex.Match(myinput,"\b\d{5}").Value.Trim()

Thanks,
Purushotham