I have this string
AnyText: "TomDickHarry" <usernameredacted@example.com>
Desired Output Using Regex
AnyText: <usernameredacted@example.com>
Help to replace anything in between AnyText:
and <usernameredacted@example.com>
with an empty string using Regex.
I am still a rookie at regular expressions. Could anyone out there help me with the matching & repla开发者_JAVA百科cing expression for the above scenario?
string ABC = "AnyText: \"TomDickHarry\" <usernameredacted@example.com>"
Regex RemoveName = new Regex("(?<=AnyText:).*(?=<)");
string XYZ = RemoveName.Replace(ABC, "");
So, this will find a regex match in the string you supplied, and on the third line, replace it with an empty string.
const string Input = @"AnyText: ""TomDickHarry"" <usernameredacted@example.com>This is.";
var result = Regex.Replace(Input, "(?<=AnyText:)([^<]*)", string.Empty);
This works for me:
string s = Regex.Replace(Input, ":(.*)<", "");
精彩评论