11.RPA Challenge - Regex to match Invoice number and Order number on consecutive lines



We have the following text which represents the OCR output from an invoice. We need a regex that determines the Order number and invoice number. They are on consecutive lines and always just under the Total Invoice line. See below bold.

Write a XAML to extract them in two string variables.

DEMO - Sliced Invoices
Suite 5A-1204
123 Somewhere Street
Your City AZ 12345
Test Business
123 Somewhere St
Melbourne, VIC 3000
test@test.com Invoice Number
Order Number
Invoice Date
Due Date
Total Due
$85.00 Sub Total
Total Invoice
January 25, 2016
January 31, 2016



RPA11.xaml (8.8 KB)


Hi All,

Here is my solution. I used a regex pattern that @ClaytonM posted in

(what a legend! I need to try and understand regex a lot more than I do right now)

StringData.Split({“Total Invoice”},System.StringSplitOptions.None)(1).Trim.Split(System.Environment.Newline(0))(0).Trim

To pick the first item after ‘Total Invoice’

StringData.Split({“Total Invoice”},System.StringSplitOptions.None)(1).Trim.Split(System.Environment.Newline(0))(1).Trim

To pick the second item after Total Invoice

Anyway here’s my attempt

Chall11_RegexInvoiceOrder.zip (94.2 KB)

I didn’t need to generate the data table and then convert it back to text (which I had from the Get full text activity) but I think I was considering going through the data table one row at a time to start off with and then I remembered the regex code Clayton had done and also the challenge was about regex right!


hey @charliefik
Thanks for the compliment :sunglasses:
One useful trick with Regex which I should have used in my post is “look-ahead” and “look-behind” (there is more info online)

"(?<=(abc))(.*)" //will pull everything AFTER "abc" not including "abc"
"(.*)(?=(abc))" //will pull everything BEFORE "abc" not including "abc"
Also, using “((.|\n|\r)*)” will pull everyting including newline and carriage return

Knowledge is power!


Thanks v much Clayton I’m going to put useful (and vaguely understandable regex code in a file so I can look it up when I need it for now until I get better at it).

Good UiPathing!