JSFiddle - React, Tailwind, and code Playground

HTML

<div id="myDiv"></div>

JavaScript

var str2= "1 dollor plus 2 dollor equal 3 dollor";

str2 = str2.replace(/(\d+)\s/g, function replaceWithReposition(x){return "$" + x});

$("#myDiv").html(str2);