I cannot remove a whitespace in a string if a variable contains that value:
var groupingSeparator = ' '; '123 456'.replace( new RegExp( groupingSeparator ), '' ); >>> as result: '123 456' But I can do it without a separate variable:
'123 456'.replace( new RegExp( ' ' ), '' ); >>> as result: '123456' I need this variable because it could also contain another value (comma, point and go on). So why we have a different behavior in the "equals" code examples? How to solve it?
EDIT: So it does not work for me locally because the value of the groupSeparator variable is not a simple whitespace. It is '\u00A0'.
'123 456'.replace( new RegExp( groupingSeparator ), '' );yields123456str = str.replace( new RegExp( g ), '' );