I have a scenario to get string between two words but the start words repeats multiple times in the text file and the end word is unique. I want the entire string between the last start word and the end word
I tried regex to get multiple matches- It returns the entire string from the first start word to end word.
Then Used Loop condition and removed the same start word and executed. But this ways takes a long time and not good pratice too.
Segmentmatch = Regex.Match(text, String.Format("Segment(.*?)0091",), RegexOptions.Singleline)
FULL TEXT:
Segement DTM* Tag DTM
0374:2* DATE/TIME QUALIFIER
Segment R4* Tag R4
0115* PORT OR TERMINAL FUNCTION CODE
Segment R2A* Tag R2A
1431* PREFERENCE
0091:3* TRANSPORTATION METHOD/TYPE CODE
Expected Result: Text between the last segment and 0091
R2A* Tag R2A
1431* PREFERENCE
Actual Result: Code returns entire Text between the first segment and 0091
DTM* Tag DTM
0374:2* DATE/TIME QUALIFIER
Segment R4* Tag R4
0115* PORT OR TERMINAL FUNCTION CODE
Segment R2A* Tag R2A
1431* PREFERENCE