I have strings that contain thousands of separators, however the string-to-number function does not want to use it correctly (using JavaScript). I am thinking about βpreparingβ a line by dividing all the thousands of separators, leaving everything else open and allowing the functions Number/ parseInt/ parseFloat(I am satisfied with their behavior differently) to solve everything else. But it seems to me that I have no idea that RegExp can do this!
Better ideas are welcome too!
UPDATE:
Sorry, the answers enlightened me as a poorly worded question. What I get is: 1) to cut thousands of delimiters only if they are, but 2) not to disturb the original string, so I get NaNs in case of invalid digits.
MORE UPDATES:
JavaScript is limited to English for parsing, so it can be assumed that the thousands separator is used for the separator. ',' for simplicity (naturally, it never matches the decimal separator in any locale, so switching to any other language should not be a problem)
Now, when analyzing the functions:
parseFloat('1023.95BARGAIN BYTES!') // parseXXX functions just "gives up" on invalid chars and returns 1023.95
Number('1023.95BARGAIN BYTES!') // while Number constructor behaves "strictly" and will return NaN
Sometimes I use rhw, free, sometimes strict. I want to find the best approach to prepare the string for both functions.
About the reality of the numbers:
'1,023.99' - , .
'1,0,2,3.99' , '1023.99', .