.net 如何在一些文本中找到所有guid?

.net 如何在一些文本中找到所有guid?,.net,vb.net,regex,guid,.net,Vb.net,Regex,Guid,我的数据库中有很多网页内容,链接如下: <a href="/11ecfdc5-d28d-4121-b1c9-1f898ac0b72e">Link</a> 该Guid唯一标识符是同一数据库中另一页的ID 我想抓取那些页面并检查断开的链接 为此,我需要一个函数,该函数可以返回页面上所有GUID的列表: Function FindGuids(ByVal Text As String) As Collections.Generic.List(Of Guid) ...

我的数据库中有很多网页内容,链接如下:

<a href="/11ecfdc5-d28d-4121-b1c9-1f898ac0b72e">Link</a>

该Guid唯一标识符是同一数据库中另一页的ID

我想抓取那些页面并检查断开的链接

为此,我需要一个函数,该函数可以返回页面上所有GUID的列表:

Function FindGuids(ByVal Text As String) As Collections.Generic.List(Of Guid) ... End Function 函数FindGuids(ByVal文本作为字符串)作为集合.Generic.List(Guid的) ... 端函数
我认为这是正则表达式的工作。但是,我不知道语法。

有更简单的方法来检查断开的链接。。。。例如,我认为我能做到:D

这也会有所帮助

static Regex isGuid = 
    new Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled);
然后

static bool IsGuid(string candidate, out Guid output)
{
bool isValid = false;
output=Guid.Empty;
if(candidate!=null)
{

 if (isGuid.IsMatch(candidate))
 {
  output=new Guid(candidate);
  isValid = true;
 }
}
return isValid;
}

[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}


建议你抓取一个免费的副本,并学习建立他们

这是一个10秒的尝试,没有优化,检查大小写并创建一个编号的捕获组:

([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})
然后你只需要遍历匹配的组

Function FindGuids(ByVal Text As String) As List(Of Guid) Dim Guids As New List(Of Guid) Dim Pattern As String = "[a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12}" For Each m As Match In Regex.Matches(Text, Pattern) Guids.Add(New Guid(m.Value)) Next Return Guids End Function 函数FindGuids(ByVal文本作为字符串)作为列表(Guid) 将Guid设置为新列表(Guid的) Dim模式为字符串=“[a-fA-F0-9]{8}-([a-fA-F0-9]{4}-{3}[a-fA-F0-9]{12}” 对于Regex.Matches中的每个m As匹配(文本、模式) 添加(新Guid(m.Value)) 下一个 返回GUID 端函数
看起来很方便。但是这个网站的许多页面需要登录,并且我必须处理其他业务规则。Total validator(高级)也将进行身份验证!我认为它实际上是专业版(不是高级版)