0

I'm having an input : string listEmail = <abc@email.com>, <xyz@mail.cc>, mail@gmail.com

How can I get value between "<" and ">"?

So the result of my input above is : abc@email.com, xyz@mail.cc

Alex
  • 727
  • 1
  • 13
  • 32
  • 1
    and what have you tried so far? – Benjamin Mar 17 '20 at 15:11
  • That input is invalid, does it compile? For us to help you, we must have a reproducible example as well as what you tried, what isn't working and expected output. – Trevor Mar 17 '20 at 15:14

1 Answers1

1

With Regex...

using System.Text.RegularExpressions;
using System.Linq;

string listEmail = "<abc@email.com>, <xyz@mail.cc>, mail@gmail.com";

Regex regex = new Regex("(?<=<).*?(?=>)");

var matches = regex.Matches(listEmail);

var result = string.Join(", ", matches.Cast<Match>());

// result is "abc@email.com, xyz@mail.cc"
rfmodulator
  • 3,638
  • 3
  • 18
  • 22