Extract the next For Each item after specific phrase

Hi, All

I have the data below as String,

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

I used an array to split in with new line and assign each one of them into correct columns. However, it is not able to handle the line “Failed in Course 005” As the way it want for the table is,

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

Is there anyway to do this?

You can do this by Regex split
the regex could be for example

([\S]+)\s([\S]+)\s([\S]+)\s(Fail\nFailed in Course [0-9]+|Pass)

for testing you can use

Save the last checked row in a string variable. If the next line starts with “Failed in Course” than add the previous line to your output

pseudo code:
for each line:
if line.contains (“Failed in Course”) → line = current_line + line
else : current_line = line