Regular Expression to capture multiple line from sample text

Hi buddy,

I have problem in UiPath extracting string via regex.
Package System.Text.RegularExpressions = 4.3.1

regex string as below:

(?im)INV(?:OICE)?\.?\s?NO\.?:?[\n\s]*?(?<invoice_no>(?:[,/]?\n?(?<invoice_detail>[\d\w][-\d\w]*[\d\w]))+)

I tried both below regex testing tools.

http://regexstorm.net/tester
This one seems meet the result I got in UiPath regex engine.

https://regex101.com/
Results of PCRE, PCRE2 flavor are close to UiPath regex engine results, but not what I want.
.NET (C#) flavor is very close to my need although my regex string is not perfectly captured.

I’d like to know which regex engine is the one UiPath is using? (.NET? C#?)
And if I would like to get result of group “invoice_detail” like .NET (C#) flavor in regex101.com, what can I do to modify the regex string?
Thanks for any advise.

Below are two possible sample text for Invoice number list
I’d like to capture all multiple line Invoice No. as a list of named capture group result “invoice_detail”, but only the first line could be captured.

ITEM NAME
TOTAL:12345 SET
INV NO:
800sdf-0052423/804sa19,8009/
8000012349/fsdfa12/
8000034568/8000052123
test:test123

ITEM NAME
TOTAL:12345 SET
INV NO: 800sdf-0052423
test:test123

@Isaac_Yeh

  1. try with regex options multiline and singleline
  2. check if the newline character is coming different in UiPath when read…for that open locals panel and check the value by clicking on magnifier may be new line is coming as \r\n generally to handle both cases \r?\n can be used

cheers

1 Like

.Net

Keep in mind that we would handle the Windows typically Linebreak composed by \r\n defensively by \r?\n

Quick n dirty

and would trim the result
strCatch = Regex.Match(strText, strPattern).Value.Trim

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

1 Like

Hi @Isaac_Yeh

Try by regexr - https://regexr.com/

(?<=INV NO:\s).*\s*.*\s*.*(?=\stest)


Hope it helps!!

Hi @Isaac_Yeh

Try this regex code:

(?<=INV\sNO:\s)[\s\S]*?(?=test)

Hope it helps!!

Hi @Anil_G

Thank you for the help. Use \r?\n DO fix my problem.

btw, for anyone who might encounter similar problem.
I checked my original text in HEX editor. It have 0x0d 0x0a in it.
I stuck in my missing of checking detail for around two days.

1 Like

@ppr

Thank you for the information of UiPath regex engine flavor (.NET).
It saves my time for trying other flavors in next regex string. :slight_smile:

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