Separate Text Content Based On RegEx

Hi,

My Query is that I have a repeated content stored in my text file which i ahve to separate into multiple outputs based on the number of times the repeated content occurs in the text file. I need to know if RegEx could solve this.

Below are the details.

Raw Text

Short Description : Need a RegEx help
Name : UiPath Admirer
Issue : RegEx
Issue Type : Medium
Long Description : Is there a way to separate the content using RegEx
Short Description : Need a RegEx help 1
Name : UiPath Admirer
Issue : RegEx 1
Issue Type : Medium
Long Description : Is there a way to separate the content using RegEx 1
Short Description : Need a RegEx help 2
Name : UiPath Admirer
Issue : RegEx 2
Issue Type : Medium
Long Description : Is there a way to separate the content using RegEx 2
Short Description : Need a RegEx help 3
Name : UiPath Admirer
Issue : RegEx 3
Issue Type : Medium
Long Description : Is there a way to separate the content using RegEx 3

Output

Output 1. Short Description : Need a RegEx help
Name : UiPath Admirer
Issue : RegEx
Issue Type : Medium
Long Description : Is there a way to separate the content using RegEx

Output 2.Short Description : Need a RegEx help 1
Name : UiPath Admirer
Issue : RegEx 1
Issue Type : Medium
Long Description : Is there a way to separate the content using RegEx 1

Output 3.Short Description : Need a RegEx help 2
Name : UiPath Admirer
Issue : RegEx 2
Issue Type : Medium
Long Description : Is there a way to separate the content using RegEx 2

Output 4.Short Description : Need a RegEx help 3
Name : UiPath Admirer
Issue : RegEx 3
Issue Type : Medium
Long Description : Is there a way to separate the content using RegEx 3

Pattern

The Label Names are always constant and will appear always in the file. “Short Description” is the field which I need to use to separate the content into multiple outputs depending on the content. Sometimes the content will have only one short description, next time it will appear more than once, so dynamically I need to identify how many times the word “Short Description” appears and accordingly i need to separate the content into that many outputs. Please advise.

there are several techniques available e.g. Regex, Line Split and filtering, Block index calculations

Regex:
Slice the blocks as following:

Short Description(.|\n)*?Long Description.*

then process each block e.g. by

(.*?)(?:\:)(.*)
refering to groups and trim the values:
grafik

Hi Peter,

I used the RegEx you gave (Short Description(.|\n)?Long Description.). It actually worked, thanks. But I ahve an issue. When the Long Description section has multiple lines it extracts only the first line and ignores the rest. So I tried using as below :

Short Description(.|\n)?Long Description.\n.*

which extracts the first and the second line only. But I need to capture all the lines of Long Description dynamically. Please help how can the above RegEx be modified to extract as said above.

Hi @Karthikeyan_Lohanathan

Try this regex expression

Regards
Sudharsan

1 Like

Hi Sudharsan,

It Worked. Thank You So Much.

1 Like

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