Extract value before and after a line break that starts with a specific value

I have a semi-structured set of text files that has the following format:

[many line breaks here with their values]
[text A]
8 …
[text B]
[many line breaks here with their values]

So far, based on the text files, the only reference point I can use is the line break that starts with “8”. It could be “8. Assigned text” or “8 Text assigned”, etc.

Intent is to extract [text A] and [text B] and assign these to their variables.

I tried with Regex and Split, but so far can’t get it to work. Let’s say the text data is stored in the variable: textData.

Hoping for anyone’s advise on this please. Thanks!

1 Like

Hi @LagunaAJ

Could you provide sample input and expected output.

Regards

1 Like

Hi @Parvathy

Sample input is a text data (from Read Text File activity) that contains:

[many line breaks here with their values]
apple
8 text here
carrot
[many line breaks here with their values]

Sample output are these values assigned to their own variables:

textA = apple
textB = carrot

From the input file, the reference point is the line break that starts with “8”. That can sometimes be “8 text here” or “8 here text”, etc.

1 Like

@LagunaAJ

I hope this is what you need

image

For before word - System.Text.RegularExpressions.Regex.Match(strval,".*(?=\n^8.*)",System.Text.RegularExpressions.RegexOptions.Multiline).Value

For After word - System.Text.RegularExpressions.Regex.Match(strval,"(?<=^8.*\n).*",System.Text.RegularExpressions.RegexOptions.Multiline).Value

cheers

1 Like

Thanks @Anil_G! Just a question, what app are you using with the screenshot you used?

2 Likes

@LagunaAJ

Here it is…you cN try regex here

Cheers

1 Like

Hi @Anil_G, thanks for the reco. I’ve been trying to actually play with the app, but I can’t get it to work. Here’s what I’m getting based on what you shared:

Can you help me diagnose this please so that I can align the expression here and that in UiPath. Thanks!

1 Like

@LagunaAJ

in the flavor on left select .net

cheers

1 Like

@Anil_G Still can’t seem to make it work even when I selected .net.

1 Like

@Anil_G It’s all good now. I had to refresh the app and it went well. Thanks!

2 Likes

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