如何在某些文本中找到所有Guid? [英] How can I find all the Guids in some text?

查看:121
本文介绍了如何在某些文本中找到所有Guid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一堆网页内容,它们的链接如下:

I've got a bunch of web page content in my database with links like this:

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

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

That Guid unique identifier is the ID of another page in the same database.

我想抓取这些页面并检查链接是否断开.

I'd like to crawl those pages and check for broken links.

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

To do that I need a function that can return a list of all the Guids on a page:


Function FindGuids(ByVal Text As String) As Collections.Generic.List(Of Guid)
    ...
End Function

我认为这是正则表达式的工作.但是,我不知道语法.

I figure that this is a job for a regular expression. But, I don't know the syntax.

推荐答案


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

这篇关于如何在某些文本中找到所有Guid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆