How to join two patterns in a single regex in a uipath variable?

Good afternoon friends;

One question please, I’m trying to join two regex in one; sometimes the date comes to me as dd/MM/yy (25/01/22) and in others like this “01 2022 Enero”


[0-9]{1,2} 20\d{2} (Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Setiembre|Octubre|Noviembre|Diciembre)

I’ve tried this way, but it’s not working for me, I’ve used the wildcard (?) because if it doesn’t find one of these patterns I don’t want to get an error.

System.Text.RegularExpressions.Regex.Matches(OutText.ToString,"([0-3][0-9](?:\/)[0-1][0-9](?:\/)[0-2][0-9])+ | [0-9]{1,2} 20\d{2} (Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Setiembre|Octubre|Noviembre|Diciembre)?")(0).Value

Hi there @Lynx,
I hope you are well.

Not the most elegant solution, but you should be able to just encapsulate each statement in brackets, then add the pipe symbol, as you have done:
([0-3][0-9](?:\/)[0-1][0-9](?:\/)[0-2][0-9])|([0-9]{1,2} 20\d{2} (Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Setiembre|Octubre|Noviembre|Diciembre))

This, for me, picks up both date formats:

Please let me know your thoughts.
Thanks once again,

1 Like

It works perfectly, as long as both types of patterns exist, if one of the two does not exist, it gives me an error. I tried varying what you recommended, but it seems I’m doing something wrong.

System.Text.RegularExpressions.Regex.Matches(OutText.ToString,"([0-3][0-9](?:\/)[0-1][0-9](?:\/)[0-2][0-9])?|([0-9]{1,2} 20\d{2} (Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Setiembre|Octubre|Noviembre|Diciembre))?")(0).Value

(([0-3][0-9](?:\/)[0-1][0-9](?:\/)[0-2][0-9])|([0-9]{1,2} 20\d{2} (Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Setiembre|Octubre|Noviembre|Diciembre)))?

I would like it to detect one or the other, but if there is no date, no error will appear.

On the web the regex check works but not when I put it in a uipath variable

Hi there @Lynx ,
Understood - If you want to check whether either side will match, you can use:
If - System.Text.RegularExpression.Regex.IsMatch(YourStringValue, YourRegexPattern)

Then do you Match check on the Then side.
Hope that makes sense.
Thanks once again,

Excuse me for my English, I have not explained well what I want;

The regex you recommended is fine; I just wanted uipath not to give me an error when in a text it doesn’t find any of the two date patterns.

For example, I used (?) to prevent uipath from giving me an error when there is no date with that pattern.




Do you need to get the first occasion matched pattern? If so, it’s better to use not Matches but Match as the following.

System.Text.RegularExpressions.Regex.Match(OutText.ToString,"([0-3][0-9](?:\/)[0-1][0-9](?:\/)[0-2][0-9])|([0-9]{1,2} 20\d{2} (Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Setiembre|Octubre|Noviembre|Diciembre))").Value

If there is no match, this returns empty string without error.


1 Like

Thank you very much @Yoichi

1 Like

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