For the SitePoint example, this jQuery replacement turns each literal <br>* sequence into a paragraph boundary:
$('body').html($('body').html().replace(/<br>*/g, '</p><p>'));
It is a narrow workaround for that exact legacy pattern. The expression removes neither a space after the asterisk nor alternate forms such as <br />, uppercase tags, or whitespace between the tag and asterisk.
What the replacement actually matches
The regular expression /<br>*/g searches for two literal characters in sequence: the exact lowercase tag <br>, followed immediately by *. The g flag applies the replacement to every match in the string.
For example, content shaped like this:
<p>First fragment<br>* Second fragment<br>* Third fragment</p>
becomes:
<p>First fragment</p><p> Second fragment</p><p> Third fragment</p>
Because the replacement is only </p><p>, the space after each asterisk remains. The result may therefore start a new paragraph with a leading space.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
Removing the asterisk and its following whitespace
If the input consistently contains an asterisk followed by optional whitespace, include that whitespace in the match:
const converted = html.replace(/<br>*s*/g, '</p><p>');
Here, s* consumes zero or more whitespace characters after the asterisk. Use this only when that whitespace is part of the legacy marker and should always be discarded.
Rank #2
If you need a source line break for readability, use a newline in the replacement, but remember that HTML rendering is governed by markup and CSS:
const converted = html.replace(/<br>*s*/g, '</p>n<p>');
Adapt the match to the real input
Inspect representative database records before choosing a pattern. The original snippet does not match these common variations:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
<br />*or<br/>*<BR>*<br> *, with a space between the tag and asterisk- HTML entities or other markers instead of a literal asterisk
For a known, controlled format, a more tolerant expression could be written, for example:
const converted = html.replace(/<brs*/??>s**s*/gi, '</p><p>');
Test any broader pattern against content that includes intentional asterisks, blank lines, existing paragraph tags, and the final fragment. A replacement that is too broad can remove text that was not a separator.
Rank #4
Why server-side conversion is usually preferable
The forum discussion’s preferred long-term fix was to transform the legacy value after reading it from the database and before sending the response to the browser.
- Visitors who disable JavaScript still receive the converted paragraphs.
- Paragraphs and line breaks can have different CSS, margins, and layout behavior, so the transformation can be reviewed as part of normal rendering.
- The database value can remain unchanged while the application consistently emits the desired HTML.
The browser-side approach changes the DOM after delivery; it does not rewrite the original response source stored on the server.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Best Value
Choosing an implementation
| Approach | Best fit | Important limitation |
|---|---|---|
| Server-side fixed-string replacement | Legacy records follow one known marker format | Requires an application change and careful output validation |
| Client-side jQuery replacement | Temporary mitigation when the page already contains the rendered HTML | Requires JavaScript and may alter layout only after page load |
| HTML parser plus targeted transformation | Markup varies or may contain nested, malformed, or unrelated HTML | More work than replacing one fixed string; choose a parser appropriate to your server language |
A regular-expression replacement is narrower than parsing HTML. A related community answer recommends an HTML parser for general HTML parsing, while allowing a regex for a fixed, known template. Do not use the short expression as a general-purpose HTML parser.
Safer browser-side handling
The original workaround rewrites the entire body’s HTML:
$('body').html($('body').html().replace(/<br>*/g, '</p><p>'));
If the legacy text is in one known element, limit the operation to that element instead of replacing unrelated page markup:
const element = document.querySelector('.legacy-content');
if (element) {
element.innerHTML = element.innerHTML.replace(/<br>*s*/g, '</p><p>');
}
This still assumes the content is trusted and that the pattern is known. Restricting the target reduces accidental changes elsewhere, but it does not turn regex into an HTML parser.
Free tools Windows power users keep installed
One-click scans. No signup required.
Validation checklist
- Confirm whether the source uses
<br>,<br/>, or<br />. - Check capitalization and whitespace around the asterisk.
- Decide whether the following space should be preserved or consumed.
- Verify that the input already has a surrounding paragraph structure that will remain valid after inserting closing and opening tags.
- Check the first and last fragments so you do not create an empty paragraph unintentionally.
- Compare the rendered result with CSS rules for both
brandp. - Prefer server-side conversion when the output must work without JavaScript.
The Bottom Line
Use replace(/<br>*/g, '</p><p>') only for the exact legacy sequence it was designed to match. Add whitespace handling when required, adapt the pattern to the actual markup, and move the conversion server-side for a durable result. Use an HTML parser when the input is not a fixed, controlled template.
Quick Recap
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.




