How can I find all the guides in some text?

I have a bunch of webpage content in my database with the following links:

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

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

I would like to crawl these pages and check for broken links.

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

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

I believe this is a regular expression job. But I do not know the syntax.

+3
source share
4 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
+8

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

+8

expresso !

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})

...

+3

.... , , http://www.totalvalidator.com/ : 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;

}

+2

Source: https://habr.com/ru/post/1704747/


All Articles