Regular expression works in regexr.com and UiPath matches activity but end result is blank

Hi,

I used a regular expression to find an invoice number in a PDF dataset by finding a specified numeric value and then retrieving the string that immediately follows it. When using regexr.com I am able to use my code to find the invoice number. I also tested the code within the matches activity in UiPath and the code returned the invoice number I was looking for. However when I am applying the regex formula into UiPath the result is blank. What am I doing wrong here?

Regards,

Jeff

Regex does not return value UiPath.docx (208.4 KB)

Hi @JeffNZ1

How did u take the value from regex output

Let’s say the output of matches is stored in output varaible.

Then use

output.ElementAt(0).ToString

1 Like

change your regex to
(?<=81-166-935)[\s]+(.*)
because when you read pdf/txt file the result might have multiple white space characters e.g.
a newline might be /r/n instead of /n so you need [\s]* instead of \s to handle that

or you can assign this to a string
System.Text.RegularExpressions.Regex.Match(txt,"(?<=81-166-935)[\s]+(.*)").Groups(1).Value

1 Like

Hello, @jack.chan !
I have the same problem as @JeffNZ1 - and I don’t know if the problem was ever solved. I’ve edited my code as you recommend, with the

Blockquote
because when you read pdf/txt file the result might have multiple white space characters e.g.
a newline might be /r/n instead of /n so you need [\s]* instead of \s to handle that

As @JeffNZ1, I’ve tested against several regex pages on the net, and as you can see, the Matches activity also returns the right output.

Nevertheless, the result turns out as blank.

Also checked this:
IEnumerable = Output
Output.Count.ToString returns 0 (zero).

Part of document:

Levering og opplæring

Hjelpemiddelformidler

Navn Live Hansen
Arbeidssted Østre Bergen kommune
Stilling Fysioterapeut
Adresse Sutrevegen 54 5050 Fana
Telefon 91111157
Treffes enklest Mand-fred 09-15

RegEx:
(?<=Hjelpemiddelformidler[\r\n][\r\n]Navn[\s])(.*)(?=[\r\n]Arbeidssted)

Regards, :norway:

@bjorn2390 - if could give the text and output you needed…I will look into it…

1 Like

I see you have used brackets…it means the Regex output is with Groups…

image

So outptut = Regexvar(0).groups(1).tostring ==> Please try this…

Or You can try this…Again Ouput = Regexvar(0).groups(1).tostring

Hi, @prasath17, and thanks for helping me out.
I changed to brackets because this was the recommandation given in this thread. So this is not intentionally from my side, to be honest I’m not familiar with groups. Still learning. It was worth a go, tho.

My origin Regex was this (without brackets):

  • (?<=Hjelpemiddelformidler\n\nNavn\s).*(?=\nArbeidssted)

which gives the same result (none).

I didn’t get what you ment about the yellowed part. Again this is on the basis of what I read in this thread (.*)

I’ve tried your suggestion. Still not getting any result :confused:

@bjorn2390 - Here you go…

Regex Pattern Link

1 Like

point_emoji_ solution

Thanks, @prasath17 !
This did the trick. Unfortunately, I’m not the starter of this thread (from 2016 :sweat_smile:), so I can’t mark your post as solution. This has to do it.

Again, thanks for helping me out.

1 Like

@bjorn2390 - no problem. I am glad that your issue got resolved. :beers:

1 Like