How to extract multiple line from text file

Dear Developer,
I need your help on this please.
That I want to extract data from text file after specific word.
Sample data in text file as below, I want only data after “Message Content:” and end of “End content.”

e.g.

Content will show after Message Content
Message Content:

ISA^00^ ^00^ ^01^003897733EPXRI ^01^KMNPROD ^220510^0302^U^00602^000054481^0^P^]
GS^SH^LG0KNCL^KMNPROD^20220510^0302^54481^X^006020
ST^856^0001
BSN^00^SX00343648^20220510^150156^0001^AS
DDM^011^20220510^000000^08
DDM^375^20220510^000000
DDM^376^20220510^000000
DDM^002^20220510^000000
DDM^250^20220503^000000
DDM^118^20220506^000000

End content.

Expected

ISA^00^ ^00^ ^01^003897733EPXRI ^01^KMNPROD ^220510^0302^U^00602^000054481^0^P^]
GS^SH^LG0KNCL^KMNPROD^20220510^0302^54481^X^006020
ST^856^0001
BSN^00^SX00343648^20220510^150156^0001^AS
DDM^011^20220510^000000^08
DDM^375^20220510^000000
DDM^376^20220510^000000
DDM^002^20220510^000000
DDM^250^20220503^000000
DDM^118^20220506^000000

Thank you so much.

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=Message Content:)[\s\S]*?(?=End content.)").Value

Regards,

1 Like

Thank you. I have apply something and result look good.

1 Like

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