I would like to turn the following:
<div>this is a $test</div>
into
<div>this is a <div>$test</div></div>
currently I have
var regexp = new RegExp('$([^\\s]*)','g'),
html = '<div>this is a $test</div>',
matched = html.match(regexp)[0]
if (matched){
html = html.replace(match, '<div>' + match + '</div>')
}
which works, but is there a more concise way of doing this?
matchonly returns an array if it found anything, otherwise it just returnsnull. So be careful there,html.match(regexp)[0]will give you atypeErrorif no match was found. – Joseph Silber Feb 17 at 1:15