Home > OS >  Replace all bold tags HTML
Replace all bold tags HTML

Time:04-30

I have HTML files and want to replace all the bold tags with STARTBOLD and ENDBOLD. This is very straightforward for the <b> and <strong> tags, but some of the tags have the bold embedded in a longer font style tag. For example,

<font style="display:inline;font-family:Times;font-weight:bold;">Risks Related to Our Business, Industry and Operations </font>\n\t\t</p>\n\t\t<p style="margin:0pt 0pt 10pt;color:#000000;line-height:100%;font-family:Times New Roman,Times,serif;font-size: 10pt;">

In this example, I would want the output to be "STARTBOLD Risks Related to Our Business, Industry and Operations ENDBOLD".

What is the most effective way to replace all versions of this tag with STARTBOLD and ENDBOLD? (Potentially using regex, but I am not familiar enough with HTML to know the exact pattern to look for since the actual tag varies over the different documents.)

Importantly, I want to replace the whole font style tag with the phrases because I am going to subsequently remove all HTML tags (but want to keep the labels for bold text).

EDIT: to clarify, based on the responses I received, I am not creating an HTML document from scratch, nor do I need to have a working HTML file. Instead, the input is HTML that I scraped and the output will eventually be just the text, but with the bold sections annotated as I described above.

CodePudding user response:

Just place this in an HTML file.

Would this help?

<strong>STARTBOLD</strong> Risks Related to Our Business, Industry and Operations. <strong>ENDBOLD</strong>

CodePudding user response:

Optionally, I thought this would help (even though your question scares people away as they are not quite sure what you want).

This is a full HTML document. Just create a file with this. That is, if it would help.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        div{
            font-family: "Ebrima";
            font-weight: 600;
            /* The default font-size is 16pixels equivalent to 1em */
            /* Should you remove the comment from the below rule the text would look bigger than it is now. */
            /*font-size: 20px;*/
        }
    </style>
    <title>Document</title>
</head>
<body>
    <div>STARTBOLD Risks Related to Our Business, Industry and Operations ENDBOLD</div>
</body>
</html>
  • Related