Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello Community,

i need your help ;-)

My input string:

Row1: STA;12345;325-5899
Row2: ML;2222;5555;GHAA
Row3: -;5881;2K5K1KKL
Row4: M2;KKN;11232

Now i want to get the string from "STA" to "M2".

The following i tryed and it failed:
STA(?s)([\S\s]*)M2

Do you have a brillant idea?!


THX a lot and regards from Germany!
Posted

1 solution

STA(.*?)M2 is enough, but you need to enable Singleline[^].
C#
var s = @"STA;12345;325-5899
ML;2222;5555;GHAA
-;5881;2K5K1KKL
M2;KKN;11232";

var re = new Regex("STA(.*?)M2", RegexOptions.Singleline);

Console.WriteLine(re.Matches(s)[0].Groups[1].Value);

Yields:
;12345;325-5899
ML;2222;5555;GHAA
-;5881;2K5K1KKL
 
Share this answer
 
v2
Comments
Otsep 28-Aug-15 3:22am    
Thx for quick solution! :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900