Reaching out to all the JS regex gurus out there. I am building a function that would remove $, white space, comma, [A-Z], [a-z] from string, leaving only float (if it exists within the string given) something like so:
var result = myFunction( 'USD $12, 345.95'); //result = 12345.95
var result = myFunction( 'ten dollars US' ); // result = false
function myFunction( weirdString ){
// some code
}
I know I can go something like (forgive me if I'm wrong):
weirdString.replace(/[&$<>"'`=\/\s]|[A-Z]|[a-z]/g, '');
isNaN( weirdString ) ? return false : return weirdString;
But what is the right way?
[&$<>"'`=\/ A-Z]a-z]. Also just use a literal space if that's all you're expecting.\smatches any whitespace character.