Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find all the Guids in some text?

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>

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.

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.

like image 792
Zack Peterson Avatar asked Nov 30 '22 20:11

Zack Peterson


1 Answers

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
like image 65
dotjoe Avatar answered Dec 05 '22 16:12

dotjoe