Regex pattern VERY slow :(

Hey UiPath forum

I got great help from you :slight_smile:

I have implemented this pattern: Regex first lines after \r\n\r\n from @ptrobot, but with 2000 transactions it takes forever.

It’s not the workflow. I have around 30 Regex extractions for each transaction and if I remove the solution from @ptrobot it runs like a charm.

Is there a reason, why this is very slow? If yes, can we make a more effecient?

Hi,

First, perhaps you should review your pattern. It seems little bit complicated.
If your requirement is just 2 lines after 2 consecutive linebreaks, the pattern might be the following.

(?<=\r?\n\r?\n)[^\r\n]+\r?\n[^\r\n]+

If you don’t want to change the pattern, can you try to use Regex instance as the following? It will make lower regex overhead to create instance in advance, in your case.

r = new System.Text.RegularExpressions.Regex("PATTERN")
for each{
     v = r.Match(inputString)
}

img20201117-5

Regards,

3 Likes

Sorry for the complicated pattern. I was trying to use “Vat nr.” as anchor which meant matching an unknown number of line breaks. This is of course always slow if your input text is very large.

Use @Yoichi’s pattern or just cut out the first part of my pattern:

From:

image

To:

(?<=(\r?\n){2})(.+\r?\n.+) 

It will give you several matches though, so be sure to pick the first one only.

image

1 Like

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