Regex "or"

Thanks for the awesome help!

I have strings with either
“asdaas
Total 23343 asda
blabla
asdasda”
or
“asda
Total, sum 54634 ghjfr
xyzblablalnlabla
asdsa”

How do I match both 23343 and 54634. E.g. I need to match the Total, but it could either be after Total or Total, sum.

The OR in Regex is “|”, quindi (Total | Total, sum)

1 Like

Cool. Can I make such that if both “Total” and “Total Sum” are present ( I dont know the order), then it should take “Total, sum”?

Or maybe you need not extract text after Total or Total, sum
but rather extract only digits?
If so, try \d+

1 Like

Yeah, but I could have digits later in the string as well, so I cant use that. Sorry.

Yes, the order matters.

You are right, you need to use (Total, sum | Total)

The regex evaluate first if “Total, sum” exist and then if “Total” exist

No thats not the case in UiPath. I’ve just tried with a Matches and the IENumerable contains both Total, sum and Total matches if they both exists in the string. I only want to have the Total, sum in the IENumerable

Can you write the Regex you used?

How about skipping the OR operator and making “, sum” optional instead?

(?<=Total(, sum)? )\d+

? means match 0 or 1 instance.

image

2 Likes

(?<=Total|Total sum)(\d*(?=))

Cool, but I get an error, when putting your pattern into regex101?

You need to check the below option:

image

But the pattern will work when you use it in UiPath.

You wrote:

But i see

Try using

(?<=Total |Total, sum )(\d*(?=)) if that’s the case

1 Like

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