How to extract multiple regex match groups only once

My text is as following and I want to extract the number at the end:

Order number 12345
Confirmation Number 12345

I have used this regex: (?:Order number|Confirmation Number)\s(\d+)

(I am getting this text through outlook email; sometimes it can come Order Number 12345 and sometimes it comes Confirmation Number 12345. Then its ok. But when these both comes togather then this regex extracts same number twice)

Is there a way to extract it once in this case?

I am new to development! Thank you in advance!

HI
welcome to UiPath community
we can use this expression to get the numbers alone
image

Cheers @MGP

Thank you for the quick reply!

I am already extracting number by using assign activity: “tmp_RegExExtract(0)Groups(1).toString”

But problem is it is extracting twice when both of these conditions comes. I want to extract only once.

Fine
if its a match or if its a group we can get the first one alone with the index position like this
matchvariable(0).tostring
or
matchvariable.Group(0).tostring

Cheers @MGP

1 Like

Hi

Then I’ll suggest you to use Match instead of Matches here in assign.

Number = System.Text.RegularExpressions.Regex.Match(StringVar,"(?:Order number|Confirmation Number)\s(\d+)").Value
1 Like

I am getting 5 different kind of email body:

Text 1: Please find Order number 12345.

Text 2: Please find Confirmation Number 34567.

Text 3: Please find Order number 23456 and also Confirmation Number 23456.

Text 4: Here there is a word Order number but number is not available

Text 5: Here there is a word Confirmation Number but number is not available

I am using “Get outlook mail messages” and iterates via “for each” activity

I am assigning String variable “EmailBodyText” to extract each email’s full body text. And then

Number = System.Text.RegularExpressions.Regex.Matches(EmailBodyText, “(?:Order number|Confirmation Number)\s(\d+)”)(0).Groups(1).Value

(I tried here Match instead of Matches also but didn’t worked)

When robot iterates through first transaction, I would like to extract 12345, second time 34567 and third time 23456 and in case of 4th and 5th text it should reply back to sender.

Can anybody suggest logic for this?

Thank you and sorry if I haven’t clearly explained situation before!!

1 Like

you have the text: “number” always before the number so use that…

I tried but it didn’t worked

i think if for every line you need to check, if the number present is only the one you need, then you could just use: \d+ expression, and if no matches you know you have the case 4 or 5…

Email body contains signature that’s why there are mobile numbers and other kind of numbers present, so I cannot use only \d+ expression, so far I have tried following expression,

Number = System.Text.RegularExpressions.Regex.Matches(EmailBodyText, “(?:Order number|Confirmation Number)\s(\d+)”)(0).Groups(1).Value

it will be impossible to help if you are not very clear in what you need… you are the one who know your requisites, if you give us the wrong examples, then people give you solutions that you after say is not good :frowning:

Fine
—use a IF condition like this
System.Text.RegularExpressions.Regex.IsMatch(strinput.ToString,”(?<=umber)(.[0-9][^\s]*)$”)

If true it will go to THEN Part where we can use the ASSIGN ACTIVITY to get the numerical value like this

str_output = System.Text.RegularExpressions.Regex.Match(strinput.ToString,”(?<=umber)(.[0-9][^\s]*)$”).ToString.Trim

Or it goes to ELSE part where we can use a SEMD OUTLOOK MAIL ACTIVITY where we ca send the mail to the person we want

Cheers @MGP

1 Like

Hi @bcorrea, my apologies if I was not very clear while simplifying my actual problem! I always appreciate every suggestions. But thank you for your time and efforts!

Hi @Palaniyappan, This logic works. Thank you very much!

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