Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. var str = 'Add 1/4 cup of sugar and 1/2 cup of blueberries.'
  2. str.replace(/(\d+)\/(\d+)/g, function(match, submatch1, submatch2) {
  3. var num1 = parseInt(submatch1);
  4. var num2 = parseInt(submatch2);
  5. return (num1 / num2).toString();
  6. });
  7. // "Add 0.25 cup of sugar and 0.5 cup of blueberries."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement