Multiply regex matches and replace them in string
问题 I'm trying to multiply the amounts in a recipe using regex replace. Here is the example HTML code <div id="ingredients"> <ul> <li>2 bananas, sliced</li> <li>1 cup frozen strawberries</li> <li>8 oz. low fat vanilla yogurt</li> </ul> </div> I got as far as here. I'm trying to find a way to multiply the matched number and then replace the old one with the multiplied one: var str = document.getElementById('ingredients').innerHTML; var regex = /[0-9]+(?:\.[0-9]*)?/g; str = str.replace(regex, "$&"