2

I have a very simple sequence that:

Reads a pdf with OCR, outputs as ReadPDF string variable

A Matches activity with a regex formula of "(?<=Order Number\n\n)\d{5}" that outputs an |Enumerable variable WorkOrder

And an Assign activity to put the result into a variable idOrder = WorkOrder(0).ToString

The Regex works in the test environment: https://regex101.com/r/dmYhAY/8

I am getting an error: Assign : Object reference not set to an instance of an object.

I've used the matches activity successfully many times before and I'm not sure why this isn't working. Is there anything I'm using in Regex, (like \n) that isn't allowed in UiPath's use of Regex or something?

Here is a screenshot of the UiPath Workflow

Code Forge
  • 27
  • 1
  • 6
  • How does _uipath_ interact with regex ? –  Jun 28 '17 at 21:36
  • Did you check if the line breaks are CRLF? Then you need `(?<=Order Number\r\n\r\n)\d{5}`. BTW, did you use lookbehinds before and did they work? – Wiktor Stribiżew Jun 28 '17 at 21:37
  • You may need to escape your \, not familiar enough with UiPath to know for sure. – adamdc78 Jun 28 '17 at 21:40
  • Use this [(?=Order Number\s+(\d{5}))](https://regex101.com/r/dmYhAY/9) it's better anyway. You don't really need to consume anything since there is no chance of overlap, and it takes the worry out of `\r?\n` And if their engine can use lookaheads, it must have a way to reference capture group 1 –  Jun 28 '17 at 21:41
  • Even `Order Number\s+(\d{5})` is better if you can reference group 1. –  Jun 28 '17 at 21:45
  • I would assume that the Regex activity in UiPath uses the regular .NET implementation. However, I think suspect that the problem is with the output from the Read OCR. Try printing out the text and check it :) – Nicolai Krüger Jun 29 '17 at 07:55
  • It does end up that UiPath uses the .Net version of Regex, so I am now using http://regexstorm.net/tester as my testing ground with great success. – Code Forge Jun 29 '17 at 19:48
  • Ultimately the Regex that worked for anyone that comes across this same question was: (?<=Order Number[\n\r]+)\d{5} and the reason given to me was... "Regarding the newlines it can appear (in) different forms depending on the environment, dealing with Microsoft apps will often be \r\n or so." – Code Forge Jun 29 '17 at 19:52
  • UiPath uses Regex in a "Matches" activity where you can input a string and use Regex as the filter to return a |Enumerable variable that you can call out each item within it 1 by 1, (example: For Each Item in the variable do an action or sequence). – Code Forge Jun 29 '17 at 19:55

1 Answers1

1

Ultimately the Regex that worked was: (?<=Order Number[\n\r]+)\d{5} and the reason given to me was... "Regarding the newlines it can appear (in) different forms depending on the environment, dealing with Microsoft apps will often be \r\n or so."

The reason for the discrepancy is that UiPath uses .Net Regex, so I am now using: http://regexstorm.net/tester for all of my Regex testing with great success and have had no more issues when bringing it over to UiPath.

Code Forge
  • 27
  • 1
  • 6