Regex variable not picking up data

We are using Regex to extract data from pdf. We are using ‘matches’ activity with IEnumerable type variable to pick numerical values. While testing the test text in RegexBuilder window it is highlighting the required values but while running the code we are not getting any data in the variable. Same process is working for other instances. We are using 2022.4.9 verison of UiPath Studio.

Hi @vaibhavsharma.v

Could you share the input and expected output. I will help you out with regex.

Regards

1 Like

Please send the input string and the xaml where you have this problem :slight_smile:

We are not getting data in the variable but it is getting highlighted in regexbuilder.

Here is the required data–
Input–Translation adjustment 82 1,410 69 42 1 1,684
As at December 31, 2016 Z 10,949 Z 99,508 Z 11,632 Z 6,165 Z 301 Z 138,555
Neerajs work-in-progress 4 10,389
Net carrying value including Capital work-in-progress as at December 31, 2016 Z 80,147
Gross carrying value:
As at April 1, 2016 2 4,815 2 40,686 2 123,471 2 15,386 2 7,259 2 317 2 291,942
Additions 40 7,269 12,191 3,917 964 7 24,388
Additions through Building combinations 7 357 6 3 343
Vaibhavsh (3) (435) (20,016) (1,225) (474) (168) (22,461)
115. Right-of-Use assets Gross carrying value: Category of Right-of-Use asset

Expected output– All the numerals from above text

Regex–(?s)(?<=\b\bTranslation adjustment .?)(-?\d{1,4}(?:,\d{3})(?:.\d+)?|-|(\d{1,4}(?:,\d{3})*(?:.\d+)?)|\b\d{4}\b)(?:\s|\n)?(?=.*Right-of-Use assets|\d+,\d+$)

Hi @vaibhavsharma.v

Can you type the expected output please.

Regards

Sure, Here you go.

82 1,410 69 42 1 1,684
31, 2016 10,949 99,508 Z 11,632 6,165 301 138,555
4 10,389
31, 2016 Z 80,147
1, 2016 2 4,815 2 40,686 2 123,471 2 15,386 2 7,259 2 317 2 291,942
40 7,269 12,191 3,917 964 7 24,388
7 357 6 3 343
(3) (435) (20,016) (1,225) (474) (168) (22,461)

Maybe try out extracting data from this string line by line with the help of a for loop and using Split String to split this string into individual lines. Line by line will be better and more stable as per my opinion.

@vaibhavsharma.v

(\d+,?\d*)

if you with braces too

\(?\d+,?\d*\)?

Hi @vaibhavsharma.v

Try this:

Input = "Translation adjustment 82 1,410 69 42 1 1,684
As at December 31, 2016 Z 10,949 Z 99,508 Z 11,632 Z 6,165 Z 301 Z 138,555
Neerajs work-in-progress 4 10,389
Net carrying value including Capital work-in-progress as at December 31, 2016 Z 80,147
Gross carrying value:
As at April 1, 2016 2 4,815 2 40,686 2 123,471 2 15,386 2 7,259 2 317 2 291,942
Additions 40 7,269 12,191 3,917 964 7 24,388
Additions through Building combinations 7 357 6 3 343
Vaibhavsh (3) (435) (20,016) (1,225) (474) (168) (22,461)
115. Right-of-Use assets Gross carrying value: Category of Right-of-Use asset"

Regex Expression:

(?<=[A-Z-a-z\s]+\s+)(\d+|\().*

Properties of Find Matching Patterns

Hope it helps!!

Hello Parvathy,
Thanks for the response but here our requirement is that we are not getting data into the variable even after ‘find matching patterns’ activity is highlighting in the sample text which implies that the regex is working fine but there some other issue which we are not able to resolve.
Also we used the below regex so that it will only pick numerals between 2 unique texts in the pdf and won’t take all the numerals of pdf.

Regex –(?s)(?<=\b\bTranslation adjustment .?)(-?\d{1,4}(?:,\d{3}) (?:.\d+)?|-|(\d{1,4}(?:,\d{3})*(?:.\d+)?)|\b\d{4}\b)(?:\s|\n)?(?=.*Right-of-Use assets|\d+,\d+$)

Hi @vaibhavsharma.v

Will the give regex by me work for you. or do you want me to correct the regular expression give by you so that it could help you.

Regards

I think regex is not the problem here. As both the regex are highlighting the required values correctly.
Things I have checked so far–

  1. Text is correctly being read by UiPath(I’ve used ‘write text file’ activity and copied the same text
    in testing).
  2. Same variable is used in both ‘find matching pattern’ and ‘write cell’ activity.
  3. There is no issue with variable scope as all the variables scope is set to the main sequence.
  4. Both upper limit unique word and lower limit unique word of regex is in the text.

Hi @vaibhavsharma.v

I hope your query resolved. If yes, please mark my post as solution to close the loop. Or if you have any queries I’m happy to help

Regards