Object reference not set to an instance of an object / variable initialization?

Hi,
Since I am new to UI Path (or programming in general), perhaps this will be silly question, but I have spent enough time searching for an answer and I can’t find it.

Scenario A. I am using matches regex look after “(?<=[p|P]olicy [n|N]umber).*” to get a specific text from text document, output is saved as IEnumerable variable say matchWord1, and then producing output in to a message. This works fine, no problems.

Scenario B. Exactly same thing, however, this time Policy number is down in a next line. So for this I have the following regex “(?<=\b[p|P]olicy [n|N]umber\s)\S+.*” and as before I want to see it in a message box.
When I run it, message box gets highlighted ant the error is “Assign: Object reference not set to an instance of an object.”

In both scenarios
To get text in the message box I am typing variable from matches output like this: matchWord2(0).value
It does not show me any errors up until I run it.
Policy number can be made up of letters and numbers
Tested regex code in regexr.com as well as in UI path, the code seems to be correct.

I was thinking I need to initialize that matches output variable (FYI that’s another issue, could not successfully initialize, so I would appreciate help for that as well.), but even more confusing thing for me is why A scenario worked without initialising, and B would need to be initialize?

Thank you in advance!

@Deimantas_Cepe

Welcome to forums

This error appears if you assign any null values to variables, so check your regex expression is returning values instead of Null Value

Hope this helps you

Thanks

@ksrinu070184

Thank you for quick responce.
When error is presented I see null
image
But when I check regex say in UI Path it seems ok, or am I missing something?

Update.

I worked out that this code (?<=[p|P]olicy [n|N]umber\s).* also picks up what I need. No more error, but the message box is blank.
image

@Deimantas_Cepe

It’s not returning any String. So you need to check the regex once again, I believe you took only part of the string and testing, I suggest to keep entire string and trim your regex expression

Hope this helps you

Thanks

@Deimantas_Cepe - If you can share the sample input text(masking any confidential data) , We can compare that with the regex you have and if necessary make an update and share the xaml with you.

@Deimantas_Cepe - If you are just trying to fetch the policy # …

Link regex101: build, test, and debug regex - For Regex pattern

Instead of configuring the expression, just try to enter the Input text and the pattern the property panel as per the above screenshot…and try it…

@prasath17

Thank you. It worked, turns out it’s not an error nor it has something to do with initialization, it was simply wrong regex code.

1 Like

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