Regex - how to capture information separately in an unstable string using regex

Hello everyone. I do not know how to express this problem but I will show you what is happening for you to understand.

I am working with a string list in which each line contains information like this:


our like




Always 2 numbers after a name, separated by “_”, then 3 numbers, then 13 numbers.

But after that it can have 0, 1 or 2 numbers before a date and finally a value and that gets in the way
I need these 2 numbers between the 13 digits and the date.

So, first I need to know if there are 0, 1 or 2 numbers in that position.

If you have 1 just take that information and assign it to a variable - call: var02

Now if it has 2 numbers, it must assign the first number to the variable
-call: var01
And then he assigns the second number to the variable
-call: var02

However, if he has neither, he must simply skip this step.

how can I do this without knowing the position in the string or even wondering if the value exists or not?

Hello @pedro.vieira - Welcome to the UiPath Forums Community!

It should be possible.

  • Can you explain your sample further / can you label the 0,1,2 number examples? I can’t see the 0 sample.

You could use Regex to obtain the string then use logic to determine the variables.
Or try multiple regex patterns - one for each variable. Then assign variables accordingly.

I have a pattern but need to know more to assist.
Pattern: (?<=\d{2}[^\d]+\d{3}\d{13}_)\w+

sample code by c#
result matchs include two numbes.
one always includes one number 1 or 2,
the other could includes oee number.
check c# documents.

string src = @“88_aaabbbccc_aaabbbccc_aaabbbccc_123_1231231231231_1_1_05/10_90,20
our like

string path = @"\b\d{2}.*._.\d{3}\d{13}(\d)?(\d?)_";
MatchCollection matchs = Regex.Matches(src,path);
foreach(Match match in matchs)

Hi @pedro.vieira

If 05/10 is the date, then the regular expression should be (?<=\d{2}_.*\d{3}_\d{13}_)\d+(_\d+)*(?=_\d{2}\/\d{2})


Use the Matches activity with the pattern above. Then use a For Each loop to go through all matched items. In the loop split the matched values like this: Parts = item.Value.Split("_"c)

If Parts.Count = 1 then Assign var01 = Parts(0)
If Parts.Count = 2 then Assign var01 = Parts(0) and var02 = Parts(1)

See attached file for an example: ExtractNumbers.xaml (10.1 KB)