You can use the fact that quantifiers are greedy:
str.replace(/(.*)<br>/, "$1");
But the disadvantage is that it will cause backtracking.
Another solution would be to split up the string, put the last two elements together and then join the parts:
var parts = str.split("<br>");
if (parts.length > 1) {
parts[parts.length - 2] += parts.pop();
}
str = parts.join("<br>");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…