Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var str = 'Add 1/4 cup of sugar and 1/2 cup of blueberries.'
- str.replace(/(\d+)\/(\d+)/g, function(match, submatch1, submatch2) {
- var num1 = parseInt(submatch1);
- var num2 = parseInt(submatch2);
- return (num1 / num2).toString();
- });
- // "Add 0.25 cup of sugar and 0.5 cup of blueberries."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement