Never seem to master those regex’s…
I need to update the total with newVal
<span class="myClass">some text Total (12)</span>
into
<span class="myClass">some text Total (13)</span>
and also without a current value
<span class="myClass">some text Total</span>
into
<span class="myClass">some text Total (13)</span>
oh, and some text can be anything
my code
newVal = 13;
$('.myClass').text( $('.myClass').text().replace(???, ???) );
Wrong approach, your code would only return the new string. To set it, use
The regex matches the string end, and (optionally) whitespaces + bracketed number before.