The reason the code on the page you're linked to works while yours doesn't, is because it's not the same regular expression. Here is what I found on this page (and similar code in several places)
r = n.text().replace( /,/g, "" )
where r is a jQuery object.
Note that the regex has inside // , not a . like the code you came across.
A comma is not a special character in regular expressions, so it does not require special treatment. The period is of particular importance. As pointed out in other answers, it matches all characters, and you need to attach it to \ if you only want to . .
Also note that .replace() not jQuery code, it is JavaScript.
The jQuery .text() method returns a JavaScript String value. So, everything you do with this string, like calling .replace() , is actually a JavaScript String method.
The difference is important if you want to investigate the problem: looking for a "javascript string replacement" will help you get more accurate information than a "jquery replace".
source share