Regex remove between

Hello, everyone!

I have a .txt document in which there are several strings.
In the .txt, there are several “Value” and “Code” fields and there are also several random strings between the different “Value” and “Code” fields.

How can I remove all strings between “Value” and “Code” in this whole .txt?

I’ll leave here the txt I’m using to understand it better
ex.txt (481 Bytes)

Based on the above txt, the final result should look like this:
ex_done.txt (304 Bytes)

Can someone help me?

Would be like this:
Read Text File -> outText
Assign: outText =
System.Text.RegularExpressions.Regex.Replace(outText,"(?<=Value:)(.*?)(?=\n)","", System.Text.RegularExpressions.RegexOptions.None)
Write Text File

1 Like

Thanks! This is perfect!
But, to understand better … in your code, where is it delimited that you should delete everything before the word “Code”?

Because I tried to use this code in my real txt (not the example I made available here), but it didn’t delete everything between the two strings.

The mistake was mine, for not having uploaded the real txt.

This is the real txt: ex1.txt (1.4 KB)
And so the final result should be:ex2.txt (1.3 KB)

The code shoud delete every string betwen the word “Uncounted” and “Sequence”

Attached is the xaml file is which giving you the desired result as mentioned in ex2.txt file

Don’t forget to click on “Mark as Solution” :slight_smile:

RemoveContentBetweenLines.xaml (6.1 KB)

2 Likes

Amazing!!! :slight_smile:
Thank you!

1 Like

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