Regex timeout if there is not match

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

  1. if there is a match, i get the result “true”
  2. 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

Hi @Joachim,

Try IsMatch()

System.text.RegularExpressions.Regex.IsMatch(PdfContent, “(?<=Regressschuldner mit Anschrift*: )(.|\r\n|\r|\n)*?(?=Geb.-Datum)”)

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.

Thanks and best regards, Jo

It seems a little bit redundant. How about the following? (Replace (.|\r\n|\r|\n)*? with [\s\S]*?

System.text.RegularExpressions.Regex.Match(PdfContent, "(?<=Regressschuldner mit Anschrift*: )[\s\S]*?(?=Geb.-Datum)").Success

Regards,

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

Hi,

If possible, can you share your input text as file? I’ll try it in my environment.

Regards,

Hi Yoichi,
i appreciate your effort.
The input test looks like this:

Auftrag für sdfsdf sdfsdfsd gtrzrtz

Schadennummer:     654612389468
Regressschuldner mit Anschrift*:  Herr  asdas  asdasd, dasdfasdf Weg 3 a, 22553
meinort
Geb-Datum, 12.04.1978
Gesetzl. Vertreter/Bevollmächtigter:
Aktueller Hauptforderungsbetrag:  65451321 EUR
Zinsen:     ab Abgabe an sdfsdf
Verjährung (ohne Gewähr):

Best regards, Jo

The thing is, sometimes its “Geb.-Datum” and sometimes “Geb-Datum”

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.

Hi,

In my environment (Studio 25.0.161, Windows project), it works without exception, as the following.

Can you also share information about your environment? Or it may be problem of your environment. (Something corrupted)

Regards,

Hello Yoichi,
thanks for your effort.
I am rolling with UiPath:

Studio 2025.0.157-cloud.18912 - 12/12/2024
Enterprise License
User-mode Installation

License Provider: Orchestrator
Activation ID: 

Microsoft Windows 11 Enterprise 64-bit
8.0.11

Anyway, i will try to test the regex in an isolated project, exactly like you did.
When i am in the office tomorrow.

Thanks and best regards,
Joachim

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

It may be your text from the pdf is too large.
If possible, can you share the pdf as a file?
or share length(size) of the text?

Regards,

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,

It doesn’t seem too large length.

To isolate cause, can you share exact exception type, using TryCatch and GetType as the following, for example? Is it MatchTimeoutException?

Regards,

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