RegEx从String.NET中删除内部Intranet链接

RegEx从String.NET中删除内部Intranet链接,.net,regex,parsing,.net,Regex,Parsing,我正在寻找一种方法,在保留标签的同时删除字符串中对内部intranet站点的所有引用 例如: Dim str As String = Nothing str &= "<a href=""http://intranet/somepage.asp"">Internal Page</a>" str &= "<a href=""http://www.external.com"">External Page</a>" Dim str As

我正在寻找一种方法,在保留标签的同时删除字符串中对内部intranet站点的所有引用

例如:

Dim str As String = Nothing
str &= "<a href=""http://intranet/somepage.asp"">Internal Page</a>"
str &= "<a href=""http://www.external.com"">External Page</a>"
Dim str As String=Nothing
str&=“”
str&=“”
任何引用都会被认为是内部的,需要用regex解析和删除

我感谢你的帮助


谢谢

虽然它不是一个正则表达式解决方案,但它同样简单。根据以上两个示例,您可以执行以下操作:

Private Function IntranetCheck(ByVal link As String) As String
    If link.ToLower().Contains("http://intranet/") Then
        Return link.Split(">")(1).Split("<")(0)
    Else
        Return link
    End If
End Function
私有函数IntranetCheck(ByVal链接作为字符串)作为字符串
如果link.ToLower()包含(“http://intranet/)那么

Return link.Split(“>”)(1.Split(我强烈建议使用进行此类处理。使用此工具,您可以执行以下操作:

HtmlDocument doc;
doc.Load(fileName);
foreach(HtmlNode anchor in doc.DocumentNode.Descendants("a").Where(n => n.GetAttributeValue("href", string.Empty).Contains("intranet")))
{
    // Change your href attribute here
    string newHref = anchor.GetAttributeValue("href", string.Empty).Replace("intranet", "somethingelse");
    anchor.SetAttributeValue("href", newHref);
}

Jacob我看到了更多关于Html敏捷包的提到,我可能需要开始研究它。谢谢你的建议。当然。在使用Html时,这是绝对必要的(IMO)。
HtmlDocument doc;
doc.Load(fileName);
foreach(HtmlNode anchor in doc.DocumentNode.Descendants("a").Where(n => n.GetAttributeValue("href", string.Empty).Contains("intranet")))
{
    // Change your href attribute here
    string newHref = anchor.GetAttributeValue("href", string.Empty).Replace("intranet", "somethingelse");
    anchor.SetAttributeValue("href", newHref);
}