Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For the specific legacy pattern <br>*, a JavaScript string replacement can turn each marker into a paragraph boundary. The short-term jQuery example below matches only that exact sequence; it does not remove the following space or handle alternate forms of the break tag.

Replace the exact `
*` pattern

The original SitePoint example had a literal `
` followed by an asterisk between text fragments. This jQuery replacement changes each exact match into a closing paragraph tag followed by an opening paragraph tag:

$('body').html($('body').html().replace(/<br>*/g, '</p><p>'));

The g flag applies the replacement to every match in the string. In the forum thread, the original poster reported that this worked for the example and treated it as a short-term solution. Read the SitePoint discussion.

The replacement does not consume the asterisk’s following space. If the input is exactly `
* ` and that space should disappear too, include it in the match:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
$('body').html($('body').html().replace(/<br>* /g, '</p><p>'));

Use that variation only when the space is consistently present and should be removed. Check the resulting content against representative input before applying it broadly.

Check whether the input matches

The first expression is literal and narrow. It will not match `
`, `
`, uppercase markup such as `
`, or whitespace between the break tag and the asterisk. A small change in the stored text can therefore leave some markers untouched.

  • Inspect the actual content, including spaces and line-break spelling.
  • Choose a match that covers the variations you intend to convert, without removing text that should remain.
  • Verify the output on examples with multiple markers and at the beginning or end of the content.

This is a string replacement for a known pattern, not a general method for parsing arbitrary HTML. A related community answer recommends using an HTML parser for general HTML parsing and reserves regex for a fixed, known template: Stack Overflow discussion of regex and HTML parsing.

Choose where to perform the conversion

Approach When it fits Trade-off
Convert on the server before sending the content The legacy format is known, and the converted paragraphs should be delivered as page content. Paragraphs and line breaks can render differently under the page’s styles. The forum reply also notes that server-delivered conversion works for visitors who have JavaScript disabled.
Convert in the browser with JavaScript A temporary workaround is needed for a fixed pattern and the content can be changed after the page loads. Visitors without JavaScript do not receive the conversion. Changing the browser’s DOM does not alter the original response source sent by the server.

The SitePoint thread favored server-side conversion as the eventual fix, while the jQuery snippet served as a workaround. If the database cannot be changed directly, conversion can still happen after the application reads the stored content and before it sends the response.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use paragraph boundaries only when the surrounding markup allows them

Replacing a break inside an existing paragraph with `

` assumes the surrounding content already forms valid paragraph markup. For example, the result should not leave an empty or unmatched paragraph at the start or end. Check the complete containing markup, not just the fragment being replaced, and compare the rendered result because paragraph styling may differ from line-break styling.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.