Get a Block of text from start of a word until the same text is not found

Hi All,

I am trying to build a regex pattern in UI Path to help me select a block of text from a text file. The file has multiple reports in it in a block format with report types.

Following is an example

REPORT: ABC
Detail Line 1
Detail Line 2

REPORT: ABC
Detail Line 3
Detail Line 4
Detail Line 5

REPORT: ABC
Detail Line 6
Detail Line 7

REPORT: XYZ
Detail Line 1
Detail Line 2

Using the above example I need the following text extracted.

REPORT: ABC
Detail Line 1
Detail Line 2

REPORT: ABC
Detail Line 3
Detail Line 4
Detail Line 5

REPORT: ABC
Detail Line 6
Detail Line 7

So basically the regex pattern should start from REPORT: ABC and extract until REPORT: ABC is not found.

Thanks,
Muffazel

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Match(text,"REPORT: ABC[\s\S]*(?=REPORT: )(?<!ABC)").Value

Regards,

Hello,

Thanks for the reply. The regex expression works but only if there are no more report types for example if there is one more report type after XYZ, like

REPORT: DEF
Detail Line 1
Detail line 2

Then the expression takes REPORT : XYZ block also.

— Muffazel

String.split(\n)
Then check if string.contains(“REPORT:ABC”)

Hi,

Sorry, I had a mistake. Can you try the following?

System.Text.RegularExpressions.Regex.Match(text,"REPORT: ABC[\s\S]*?((?=REPORT: )(?!REPORT: ABC)|$)").Value

Regards,

1 Like