I want to extract email id between < >
for example.
input string : "abc" <abc@gmail.com>; "pqr" <pqr@gmail.com>;
output string : abc@gmail.com;pqr@gmail.com
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\" <abc@gmail.com>;", '<', '>')
you will get
abc@gmail.com
string input = @"""abc"" <abc@gmail.com>; ""pqr"" <pqr@gmail.com>;";
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