JSFiddle - React, Tailwind, and code Playground

JavaScript

alert('This is a string<br>\nnext line<br>\n<br>'.replace(/(<br>\s*)+$/,''));