Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace any character before <[email protected]> with an empty string

Tags:

c#

regex

I have this string

     AnyText: "jonathon" <[email protected]>

Desired Output Using Regex

     AnyText: <[email protected]>

Omit anything in between !

I am still a rookie at regular expressions. Could anyone out there help me with the matching & replacing expression for the above scenario?

like image 498
Derek Avatar asked Jan 21 '26 19:01

Derek


1 Answers

Try this:

string input = "jonathon <[email protected]>";
string output = Regex.Match(input, @"<[^>]+>").Groups[0].Value;
Console.WriteLine(output); //<[email protected]>
like image 69
The Mask Avatar answered Jan 23 '26 08:01

The Mask



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!