Get Invoice Number from starting or end

Hi I need to extract the invoice number from the email subject which is generally at the end of the email subject.
For example: “Settlement Invoice: Xyz company 2023 final deal 653457”
“ 653457 Settlement Invoice: Xyz company 2023 final deal ”

From above how do I need to extract the"653457" number only.

Thanks in Advance

If the invoice number’s always 6-digits you could use regular expressions to fetch the 6-digit number from the text [0-9]{6}

Hi @Binod_Kumar_Biswal

You can try using this RegEx pattern:



UiPath Syntax:

extractedValue = System.Text.RegularExpressions.Regex.Match(yourString,"\b(\d+)$").ToString

Hope this helps,
Best Regards.

It’s not mandatory that invoice number will be 6 digits, it will be number followed by email subject or email subject followed by number

Hi Arjun,

Thanks for the help
But this expression is only working if the invoice number is in the end of email subject not at the first. Can you please share what changes need to be done if the invoice number will be in the starting of the email subject also ?

Hm if there’s no fixed pattern to the invoice number, regular expressions won’t work. If you’re certain that the invoice number will always be the first word or the last word, perhaps splitting the email subject and fetching the first and / or the last word can be done. But you’ll still need to verify afterwards whether the word you’ve fetched is an invoice number or not.

Strings.Split("653457 Settlement Invoice: Xyz company 2023 final deal", " ").First or Strings.Split(“Settlement Invoice: Xyz company 2023 final deal 653457”).Last



Well, in that case, you can the following pattern:



You can also take a group of data & get the number, just in case the string contains any other combination of 6 digits.

Hope this helps,
Best Regards.

Invoice number can be anything ranging from 2 digit to 8 digit then only this is gix either the invoice number will came at starting or at the end of the email subject.


Please try this


This will check for 2 to 8 digits at the start or end


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