Regex Match problem ( Assign: Object reference not set to an instance of an object)

HI All,
I am using screen scraping to pull details from a invoice sheet.
I have managed to write RegEx expressions for getting most of the information I need.
However, I am facing trouble getting value from the scraped text.

Even the RegEx builder on UiPath highlights the value. But when I run the robot, the CastIterator on the local variables shows nothing and then the assign activity throws the error.

The RegEx Pattern I have tested on various website that works is below:

([0-9]{1,})(?=\s[a-z]{1,}\s[^a-zA-Z]{1,}\s[A-Z]{1,}\n[a-z])

The sample text is below (Bold letters are the values which I want to get):

3/3
INVOICE SHEET
INVOICE NO. R99999W1 N/YI 99.9 KGS L 999 CM 99999-9999
ORDER NO. 123456789 G/N 99. 9 K63 N 68 CM ABCD
PACKING N0. 999999—9999 H 99 CM TAILAND
STYLE 0F PACKAGE PALLET N’MENT 0.999 M3 C/N0.1 0F 1
S/NO. : 999999
COUNTRY
TID OF
ATT PART NO. DESCRIPTION QUANTITY UNIT PRICE AMOUNT ORIGIN
8W-B 65432-7777 Rob VP-624/R08A (S/N012345678) 100 set 99,999.00 990, 999. 00 JAPAN
set consist of 1 Robot main unit 1 pc
2 Robot controller 1 pc
6 Software (WINMMMS III Trial DVD) 1 pc
, 8 Direction Indication Label 1 pc
9 AL Label 1 pc
11 Pin (LPT6—30) 1 pc
123456-5432 Motor & Encoder cable 2m (RC8) 1 pc 15,485.00 15,485.00 JAPAN
TOTAL 1 pc 999, 999. 00
1 set

Does anyone know how to do ?

Hey

Regex.Match(strResult, "([0-9]{1,})(?=\s[a-z]{1,}\s[^a-zA-Z]{1,}\s[A-Z]{1,}\n[a-z])").Value

it is working for me


image

Hello,
Thank for your help.

But it still dosen’t work…
Like this :

can you share your workflow?

can you paste here the value of your A variable, if possible don’t change anything

Hi @TakeshiC ,

Could you try performing a Debug and check in the Immediate Panel the variable values used.

Also check if there are duplicate variables created.

Like this

“3/3” & vbnewline &
“INVOICE SHEET” & vbnewline &
“INVOICE NO. R99999W1 N/YI 99.9 KGS L 999 CM 99999-9999” & vbnewline &
“ORDER NO. 123456789 G/N 99. 9 K63 N 68 CM ABCD” & vbnewline &
“PACKING N0. 999999—9999 H 99 CM TAILAND” & vbnewline &
“STYLE 0F PACKAGE PALLET N’MENT 0.999 M3 C/N0.1 0F 1” & vbnewline &
“S/NO. : 999999” & vbnewline &
“COUNTRY” & vbnewline &
“TID OF” & vbnewline &
“ATT PART NO. DESCRIPTION QUANTITY UNIT PRICE AMOUNT ORIGIN” & vbnewline &
“8W-B 65432-7777 Rob VP-624/R08A (S/N012345678) 100 set 99,999.00 990, 999. 00 JAPAN” & vbnewline &
“set consist of 1 Robot main unit 1 pc” & vbnewline &
“2 Robot controller 1 pc” & vbnewline &
“6 Software (WINMMMS III Trial DVD) 1 pc” & vbnewline &
“, 8 Direction Indication Label 1 pc” & vbnewline &
“9 AL Label 1 pc” & vbnewline &
“11 Pin (LPT6—30) 1 pc” & vbnewline &
“123456-5432 Motor & Encoder cable 2m (RC8) 1 pc 15,485.00 15,485.00 JAPAN” & vbnewline &
“TOTAL 1 pc 999, 999. 00” & vbnewline &
“1 set”

By the way, the variable’s attribute is string.

Hey

why are you adding those vbnewline and then trying to extract your value as whole string?
i mean it should be an entire string without those vbnewline, or just keep the line you need to extract and make the regex there

Hi,

It might be linebreak matter. Can you try the following pattern?

([0-9]{1,})(?=\s[a-z]{1,}\s[^a-zA-Z]{1,}\s[A-Z]{1,}\r?\n[a-z])

Regards,

Because system will show " End of expression expected", if I try to write in a new line and don’t add vbnewline in meanwhile.
Anyway, I have already solved my problem, thank you again!

1 Like

It works well !
Thank you !

1 Like

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