I want to extract email id between < >
for example.
input string : "abc" <[email protected]>; "pqr" <[email protected]>;
output string : [email protected];[email protected]
Without regex, you can use this:
public static string GetStringBetweenCharacters(string input, char charFrom, char charTo)
    {
        int posFrom = input.IndexOf(charFrom);
        if (posFrom != -1) //if found char
        {
            int posTo = input.IndexOf(charTo, posFrom + 1);
            if (posTo != -1) //if found char
            {
                return input.Substring(posFrom + 1, posTo - posFrom - 1);
            }
        }
        return string.Empty;
    }
And then:
GetStringBetweenCharacters("\"abc\" <[email protected]>;", '<', '>')
you will get
string input = @"""abc"" <[email protected]>; ""pqr"" <[email protected]>;";
var output = String.Join(";", Regex.Matches(input, @"\<(.+?)\>")
                                    .Cast<Match>()
                                    .Select(m => m.Groups[1].Value));
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With