somevar = ' 150,00 $';
someothervar = '$25.0;
I want to remove dollar signs, spaces, commas or dots.
Tried somevar.replace(/('$'|' '|,|\.)/g,''); returned  15000 $ (leading space).
So it looks like the comma is being removed but not everything else?
I could go like this:
somevar.replace(/\$/g,'').replace(/ /g,'').replace(/,/g,'')
But surely there's a more 'elegant' way?
You could use /[$,.\s]/g:
' 150,00 $'.replace(/[$,.\s]/g, '');
// "15000"
'$25.0'.replace(/[$,.\s]/g, '');
// "250"
Your regular expression wasn't working because you needed to escape the $ character, and remove the single quotes. You could have used: /\$| |,|\./g.
Alternatively, you could also just replace all non-digit character using /\D/g:
' 150,00 $'.replace(/\D/g, '');
// "15000"
'$25.0'.replace(/\D/g, '');
// "250"
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With