JavaScript parseFloat on regex parameter returning NaN

I am trying to manipulate some float values inside of a string by a certain amount. To do so I have the following:

var string = '<path d="M219.6,-71.4C249,19.1,212.7,130.9,135.7,186.8C58.8,242.7,-58.8,242.7,-135.7,186.8C-212.7,130.9,-249,19.1,-219.6,-71.4C-190.2,-161.8,-95.1,-230.9,0,-230.9C95.1,-230.9,190.2,-161.8,219.6,-71.4Z" />';
var regex = /[+-]?([0-9]*[.])?[0-9]+/g;
console.log(string.replace(regex, parseFloat("$&") + 300));
Answer:1

Your code is equivalent to writing

var temp = parseFloat("$&") + 300;
document.body.innerText = string.replace(regex, temp);

because function arguments are evaluated before calling the function. "$&" only has special meaning if it's literally in the replacement string that replace() gets, it doesn't have any special meaning to parseFloat(), and it's not possible for replace() to reach into the parseFloat() call and modify the parameter.

If you want to call a function to determine the replacement, you need to pass a function reference to the replace() function, not an expression containing the function call.

var string = '<path d="M219.6,-71.4C249,19.1,212.7,130.9,135.7,186.8C58.8,242.7,-58.8,242.7,-135.7,186.8C-212.7,130.9,-249,19.1,-219.6,-71.4C-190.2,-161.8,-95.1,-230.9,0,-230.9C95.1,-230.9,190.2,-161.8,219.6,-71.4Z" />';
var regex = /[+-]?([0-9]*[.])?[0-9]+/g;
var newString = string.replace(regex, match => parseFloat(match) + 300);
console.log(newString)
Answer:2

I looking to post leads from my MSSQL database to a third party site. I've created a page that queries the database and inserts values into form fields so that I can manually press a submit button. ...

I looking to post leads from my MSSQL database to a third party site. I've created a page that queries the database and inserts values into form fields so that I can manually press a submit button. ...

I've got this Electron app (using NodeJS, Bootstrap, AngularJS) with some text input fields that can be edited. I have a button that triggers a window.alert() After it has been triggered, the text ...

I've got this Electron app (using NodeJS, Bootstrap, AngularJS) with some text input fields that can be edited. I have a button that triggers a window.alert() After it has been triggered, the text ...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. cancun
  6. canada goose
  7. cane corso
  8. canes
  9. canadian prime minister
  10. cancun flights
  11. canker sore
  12. candy
  13. cancer
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis

From the code underneath, I want to remove the previous instances of codemirror, that is both "hello" and "hii" before I can add another instance. The jQuery is not working. Also, if I console.log($('...

From the code underneath, I want to remove the previous instances of codemirror, that is both "hello" and "hii" before I can add another instance. The jQuery is not working. Also, if I console.log($('...

I have a folder in Google Drive and I need to embed it on my website. I used this code: <iframe src="https://drive.google.com/embeddedfolderview?id=0B-cjMH6T4IV5bzlkUmpTWkhQOTg#grid" width="700" ...

I have a folder in Google Drive and I need to embed it on my website. I used this code: <iframe src="https://drive.google.com/embeddedfolderview?id=0B-cjMH6T4IV5bzlkUmpTWkhQOTg#grid" width="700" ...

  1. embed google drive video
  2. embed google drive folder
  3. embed google drive pdf
  4. embed google drive image
  5. embed google drive video squarespace
  6. embed google drive video in powerpoint
  7. embed google drive file
  8. embed google drive audio
  9. embed google drive link
  10. embed google drive folder wordpress
  11. embed google drive video in gmail
  12. embed google drive wordpress
  13. embed google drive folder iframe
  14. embed google drive video in email
  15. embed google drive document
  16. embed google drive video in slides
  17. embed google drive document in website
  18. embed google drive video in canvas
  19. embed google drive search
  20. embed google drive video in wordpress