0

I have a multi-line string :

 273: ( 34, 50, 82) #223252 srgb(34,50,82)
 204: ( 42, 49, 43) #2A312B srgb(42,49,43)
 224: ( 84, 85, 60) #54553C srgb(84,85,60)
 143: (148,141,114) #948D72 srgb(148,141,114
 120: (166,151, 50) #A69732 srgb(166,151,50)
 107: (168,157, 97) #A89D61 srgb(168,157,97)
 206: (215,181, 82) #D7B552 srgb(215,181,82)
 222: (222,198, 82) #DEC652 srgb(222,198,82)
1144: (239,184, 31) #EFB81F srgb(239,184,31)
1382: (241,200, 32) #F1C820 srgb(241,200,32) 

I need to trim it using regex , whatever comes before '#' So far I am able to trim it from the first line using the pattern :

string pattern = @".+?(?=#)";

Output :

 273: ( 34, 50, 82)

Expected output :

273: ( 34, 50, 82)
204: ( 42, 49, 43)
.
.
1382: (241,200, 32)

Even if out put is in a single array should be fine but I am getting only the first line , I know I can iterate through each line and get the output , but is there any better approach without iteration? How do I get the expected output ? Any help would be great

coder3521
  • 2,608
  • 1
  • 28
  • 50
  • 1
    Do you mean you are using `Regex.Match` instead of `Regex.Matches`? – Wiktor Stribiżew Dec 19 '17 at 11:22
  • Thanks @WiktorStribiżew , for immediate , consider me noob regex.Matches is giving the required output , Now I need to iterate through the Match Collection to get the required output . – coder3521 Dec 19 '17 at 11:26
  • `Regex.Matches(s, pat).Cast().Select(m=>m.Value).ToList()` – Wiktor Stribiżew Dec 19 '17 at 11:29
  • I don't understand the requirement for Regex or no iteration. Is it to be _sexy_? Iterating the lines and using `split` or `indexof` and `substring` would be both easy to read and fast. – Equalsk Dec 19 '17 at 11:33

0 Answers0