Extract the next line after specific phrase

Hi, All

I have the data below,

Name Age University Pass/Fail
Peter 20 abcUniversity Pass
Terry 19 xyzUniversity Fail
Failed in Course 005
Chris 21 tyuUniveristy Pass

I have already using the SubString to extract the data above but without the “Failed in Course 005”. Is there any way to also extract the next line after the phrase “Fail”? The way I want is the final column of Terry to be “Fail Failed in Course 005”

Hello @Hugo_Pang

Yes, its possible with Regex :smiley:

Thanks for the text sample and output. Some more information on the pattern would be helpful when developing a solution :slight_smile:

Will the text change?
Is it always on a new line?
Is it always 3 digits?

Hugo_Pang.xaml (4.9 KB)
I have made a sample workflow which will change depending on the course number.




1 Like

Hi Steven, Thank you so much for your reply.

However, I am not able to download the workflow due to the restriction of my work environment. Would it be able to share the step of your workflow?


1 Like


What I did in the workflow…sure :slight_smile:

Step 1: Create a sequence.
Step 2: Insert an Assign activity. Create a string variable called “Str_Sample” and then insert the following:
Str_Sample = (Your sample text)

Step 3: Insert ‘Matches’ Activity
Step 4: Update properties for ‘Matches’ Activity

  • Under Input: insert ‘Str_Sample’
  • Pattern: Insert this pattern “(Fail)\n(Failed in Course \d+)”
  • Result: Create new variable (using ‘ctrl + k’) and name the variable MatchesResult

Step 5: Insert Write line activity.
Type in the write line activity the following:
MatchesResult(0).Groups(1).tostring + " " + MatchesResult(0).Groups(2).tostring

Step 6: Run :blush:

Whole of workflow view:

Hey @Hugo_Pang

If you want to learn Regex - feel free to check out my Regex MegaPost.

It will take you on my 'Learning Regex journey" and will get you using Regex in a matter of hours.

Also - here is a GREAT video on how to use Regex :smiley:

1 Like

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