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 357931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:15:07+00:00 2026-05-12T12:15:07+00:00

This is a follow up to another question of mine. The solution I found

  • 0

This is a follow up to another question of mine. The solution I found worked great for every one of the test cases I threw at it, until a case showed up that eluded me the first time around.

My goal is to reformat improperly formatted tag attributes using regex (I know, probably not a fool-proof method as I’m finding out, but bear with me).

My functions:

Public Function ConvertMarkupAttributeQuoteType(ByVal html As String) As String
    Dim findTags As String = "</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>"
    Return Regex.Replace(html, findTags, AddressOf EvaluateTag)
End Function

Private Function EvaluateTag(ByVal match As Match) As String
    Dim attributes As String = "\s*=\s*(?:(['""])(?<g1>(?:(?!\1).)*)\1|(?<g1>\S+))"
    Return Regex.Replace(match.Value, attributes, "='$2'")
End Function

The regex in the EvaluateTag function will correctly transform HTML like

<table border=2 cellpadding='2' cellspacing="1">

into

<table border='2' cellpadding='2' cellspacing='1'>

You’ll notice I’m forcing attribute values to be surrounded by single quotes — don’t worry about that. The case that it breaks on is if the last attribute value doesn’t have anything around it.

<table width=100 border=0>

comes out of the regex replace as

<table width='100' border='0>'

with the last single quote incorrectly outside of the tag. I’ve confessed before that I’m not good at regex at all; I just haven’t taken the time to understand everything it can do. So, I’m asking for some help adjusting the EvaluateTag regex so that it can handle this final case.

Thank you!

  • 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-12T12:15:07+00:00Added an answer on May 12, 2026 at 12:15 pm

    richardtallent’s explanation of why the regex wasn’t working pointed me in the right direction. After playing around a bit, the following replacement for the EvaluateTag function seems to be working.

    Can anybody see anything problematic with it? The change I made is in the last group after the pipe. Maybe it could even more simplified further?

     Private Function EvaluateTag(ByVal match As Match) As String
       Dim attributes As String = "\s*=\s*(?:(['""])(?<g1>(?:(?!\1).)*)\1|(?<g1>[^>\s]+))"
       Return Regex.Replace(match.Value, attributes, "='$2'")
     End Function
    

    If no one responds I’ll probably accept this as the answer. Thanks again!

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

Sidebar

Related Questions

This is a follow up to another question of mine where I first found
This is a follow-up question to another SO question of mine . I have
This is a follow-up to another question I asked earlier today. I am creating
This is a follow on from another question i made I have this query
This is a follow on from another question, my question is regarding the use
This is a more specific question to follow up on [another question that I
This question is a follow-up from another SO question from a while back: zooming
This is a follow up of another question I asked last night. My problem
This is a follow up question from another post but that post was answered.
This is a follow up question to this one: Syntax confusion (do block) So,

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.