C#正则表达式的问题

来源:百度知道 编辑:UC知道 时间:2024/05/11 02:20:02
有一串长字串,我想把所有<(中间有不同的字串)>的字串去除,如:
dfshggfdf<sag>asdfsdg
去除后得
dfshggfdfasdfsdg
这个应该怎么做呢?

您好,

您可以调用Regex类的Replace方法将正则表达式匹配的部分替换为空,例如:

private string ReplaceWithRegularExp(string strInput)
{
Regex reg = new Regex(@"<.*>");
reg.Options = RegexOptions.Multiline;
return reg.Replace(strInput, "");
}

希望对您有帮助。

正则表达式是:

<.*?>

string str="dfshggfdf<sag>asdfsdg".Replace("<sag>","")
不就行了吗!