Hello,
i have a regex and UiPath times out, when there is not match.
If there is a match i can get the value and the result.
Example:
System.text.RegularExpressions.Regex.Match(PdfContent, “(?<=Regressschuldner mit Anschrift*: )(.|\r\n|\r|\n)*?(?=Geb.-Datum)”).Success
if there is a match, i get the result “true”
if there is not match, UiPath has a timeout.
The regex is a positive lookbehind combined with a positive lookahead.
However, the regex itself works fine, e.g. on https://regex101.com/ , which to me proves that the regex is correct.
Additionally i tried to execute the regex with the activity “Find Matching Patterns”, but the timeout issue still exists.
If anyone has an idea how to solve this issue, it would be much appreciated.
Best regards, Jo
Hello mrv.raj,
thank you for your quick reply.
In fact, i did try .isMath.
It didn’t work either. I presume that UiPath cannot process positive lookbehind combined with positive lookahead.
Hello Yoichi,
that’s not the issue.
The problem is that UiPath does not recognize the match between the positive lookbehind and the positive lookahead. Regardless if i use your suggestion or not
This has nothing to do with the middle section.
Best regards, Jo
Yes it can. The problem is you have an * inside your positive lookbehind. Regex doesn’t like this. You have to escape the *. You also have a period inside the positive lookahead but that period doesn’t exist in the test text you gave us.
(?<=Regressschuldner mit Anschrift\*:)(.|\n)*(?=Geb-Datum)
Regex101.com is an invaluable tool for building Regex expressions:
Hello Postwick,
the asterisk works fine for me.
The problem is, when there is no match. Then UiPath has a timeout instead of delivering return value false.
Best regards, Jo
The * does not work fine, in your expression it is being interpreted as a regex character (ie wildcard) rather than a literal character. This is why you should escape it with \ so it is treated as a literal character.
Your expression was wrong, which is probably why you were getting the timeout. Try with the expression I gave you. If you just want to know if the text is found, then use System.Text.RegularExpressions.RegEx.IsMatch instead of Match. IsMatch returns true or false, Match does not.
Hello postwick,
you are right and i apologize. * does not work and requires to be escaped.
The example in my post is a typo, in UiPath and in regex101 (which i use to develop the regexes) i indeed utilized the backslash (i would not work without):
System.text.RegularExpressions.Regex.Match(PdfContent, “(?<=Regressschuldner mit Anschrift*: )(.|\r\n|\r|\n)*?(?=Geb.-Datum)”).Success
But regardless, UiPath does not deliver a false here, when there is not match.
It has a timeout. That is my problem.
Best regards, Jo
Regex.Match does not return true or false, it returns the matching text. Use Regex.IsMatch to return true or false. Use IsMatch and the expression I gave you.
Hello Yoichi,
i could reproduce your result True / False.
But why does it not work in my process?
One difference is, that i read from a pdf file.
Why does the timeout occur …
there has to be something that jeopardizes the regex result when there’s no match.
Thanks and best regards, Jo
Hello Yoichi,
due to DSGVO matters i cannot share the original input.
However, the length of the file is
PdfContent.Length
2059
If i cut the pdf text, remove the leading @ and execute the regex, the result is True in case there is no match.
It must be related to the text that has been extracted from the pdf file.
Thanks and best regards, Jo
Hi Yoichi,
i am sorry, my description is a little unprecise.
It is not really a timeout, but UiPath is stuck in an endless loop and i have to quit manually.
Possibly the string contains some sort of incorrect “end of string” or “end of file” terminator after being extracted from the pdf with the activity “ReadPDFText”.
Do you accidentally know how to show the EOF character. It must be some kind of ascii code character.
Best regards, Jo