Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3609940
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:41:26+00:00 2026-05-18T21:41:26+00:00

I was able to extract href value of anchors in an html string. Now,

  • 0

I was able to extract href value of anchors in an html string. Now, what I want to achieve is extract the href value and replace this value with a new GUID. I need to return both the replaced html string and list of extracted href value and it’s corresponding GUID.

Thanks in advance.

My existing code is like:

Dim sPattern As String = "<a[^>]*href\s*=\s*((\""(?<URL>[^\""]*)\"")|(\'(?<URL>[^\']*)\')|(?<URL>[^\s]* ))"

Dim matches As MatchCollection = Regex.Matches(html, sPattern, RegexOptions.IgnoreCase Or RegexOptions.IgnorePatternWhitespace)

If Not IsNothing(matches) AndAlso matches.Count > 0 Then
    Dim urls As List(Of String) = New List(Of String)

    For Each m As Match In matches
      urls.Add(m.Groups("URL").Value)
    Next
End If

Sample HTML string:

<html><body><a title="http://www.google.com" href="http://www.google.com">http://www.google.com</a><br /><a href="http://www.yahoo.com">http://www.yahoo.com</a><br /><a title="http://www.apple.com" href="http://www.apple.com">Apple</a></body></html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:41:27+00:00Added an answer on May 18, 2026 at 9:41 pm

    You could do something like that:

    Dim pattern As String = "<a[^>]*href\s*=\s*((\""(?<URL>[^\""]*)\"")|(\'(?<URL>[^\']*)\')|(?<URL>[^\s]* ))"
    Dim urls As New Dictionary(Of Guid, String)
    Dim evaluator As MatchEvaluator = Function(m)
        Dim g As Guid = Guid.NewGuid()
        Dim url = m.Groups("URL").Value
        urls.Add(g, url)
        Return m.Value.Replace(url, g.ToString())
    End Function
    
    Dim newHtml = Regex.Replace(html, pattern, evaluator)
    

    In the end, newHtml has the following value:

    <html><body><a title="329eb2c4-ee51-49fa-a8cd-2de319c3dbad" href="329eb2c4-ee51-49fa-a8cd-2de319c3dbad">http://www.google.com</a><br /><a href="77268e2d-87c4-443c-980c-9188e22f8496">http://www.yahoo.com</a><br /><a title="2941f77a-a143-4990-8ad7-3ef56972a8d4" href="2941f77a-a143-4990-8ad7-3ef56972a8d4">Apple</a></body></html>
    

    And the urls dictionary contains the following entries:

    329eb2c4-ee51-49fa-a8cd-2de319c3dbad: http://www.google.com
    77268e2d-87c4-443c-980c-9188e22f8496: http://www.yahoo.com
    2941f77a-a143-4990-8ad7-3ef56972a8d4: http://www.apple.com
    

    By the way, note that regular expressions are not the best option for parsing HTML… A tool like HTML Agility Pack would be more adequate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to extract a couple of key value pairs (if
What I need is to be able to extract the files in a .rar
I would like to be able to extract a number from within a string
In Nant, I would like to be able to extract the last name of
I want to be able to capture the exception that is thrown when a
I want to be able to do: For Each thing In things End For
I need to be able to create basic MS Project items (tasks, projects, resources,
So I have a URL that I need my Flash movie to extract variables
Hi I have been able to extract a VARCHAR to a date using string_to_date
I am looking at being able to extract all plain text and analyse/amend from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.