Regex issue at having parenthesis

Hi all,

I am having an issue related to regex at reading pdfs:

image

I want to get the name of car. From Sportage or Kia until the last character before the amount. The issue is that sometimes there is “(MYXX)” and if I put the following code, it gets all you can see:

(?<=^\w{17}\s+)[\w.-,\s]+[\s(\w)]+

How could I do it?

Thanks :slight_smile:

Hi,

Can you try the following pattern?

(Sportage|KIA).+?\(.*?\)

or

(?<=[A-Z0-9]{17}\s).+?\(.*?\)

Regards,

1 Like

Thanks @Yoichi!! :slight_smile: Could you explain me what is it doing “.+?(.*?)”? As it is first time I see it :slight_smile:
Many thanks!!

Hi,

.+?\(.*?\)

In this case, ? means lazy quantifier. Please check the following document.

And \ is for escaping parenthesis.

Regards,

2 Likes

Hello,

I am doing this regex code, and it works in regexr.com but in Uipath the output is empty, and I have activated multiline option:

UiPath: system.Text.RegularExpressions.Regex.Match(pdf, “(?<=^\d{6,}\s[*,\w,\s,,]+[\d,,.]+\s[\d,,.]+\s\w\s[\d,,.]+\s(.*?))[\d,,]+$”, RegexOptions.Multiline).Value.ToString

Do you know why is empty in UiPath?

Thanks

Hi,

It might be line break matter.

Can you add \r? at the end of the pattern as the following?

[\d,\,]+\r?$

Regards,

1 Like

Perfect! It works :slight_smile:

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