How to remove a set of words using Regex when one word is constant and other is not constant

image

I need to remove everything from 117 C to end of the line DATE.
The colored ones are the only constants. I don’t want to remove the line Balance

Thanks

HI,

Can you try either of the following?

System.Text.RegularExpressions.Regex.Match(yourString,"BALANCE\s+[\d.,]+").Value

OR

System.Text.RegularExpressions.Regex.Replace(yourString,"117 C[\s\S]+?DATE:.*\n","")

Regards,

Hi @sunilkanth ,

If you would want to retain data from the Balance, then maybe we can use that as the key and then capture upto the end of data.
Regex Expression:

(?=BALANCE)[\s\S]+

I have data before 117C as well and the word balance is not constant

I cannot use the first one because BALANCE is not constant.

And the second one selects up to the first date value ie.06.10.202

@sunilkanth ,

In that case, the Solution provided by @Yoichi with Regex.Replace() should help you get the required output.

Its select only upto the first date

Hi,

If you need to remove from “117 c” to the last date, the following will work.Can you try this?

System.Text.RegularExpressions.Regex.Replace(yourString,"117 C[\s\S]+DATE:.*\n","") 

Regards,